ELisp: Make HTML Ruby Annotation
Here's a command to turn text into a HTML ruby annotation markup.
(defun xah-html-markup-ruby (&optional @begin @end) "Wrap HTML ruby annotation tag on current line or selection. Chars inside paren are wrapped with “rt” tag. For example abc (xyz) becomes <ruby class=\"ruby88\">abc <rt>xyz</rt></ruby> When called in lisp code, *begin *end are region begin/end positions. URL `http://xahlee.info/emacs/emacs/elisp_html-ruby-annotation-markup.html' Version 2017-01-11" (interactive) (progn (if (null @begin) (progn (if (use-region-p) (progn (setq @begin (region-beginning)) (setq @end (region-end))) (progn (setq @begin (line-beginning-position)) (setq @end (line-end-position))))) (progn (setq @begin (line-beginning-position)) (setq @end (line-end-position)))) (save-restriction (narrow-to-region @begin @end) (progn (goto-char (point-min)) (while (search-forward "(" nil "NOERROR") (replace-match "<rt>"))) (progn (goto-char (point-min)) (while (search-forward ")" nil "NOERROR") (replace-match "</rt>"))) (goto-char (point-min)) (insert "<ruby class=\"ruby88\">") (goto-char (point-max)) (insert "</ruby>"))))
see also HTML “ruby” Annotation Example