Elisp: Make HTML Ruby Annotation

By Xah Lee. Date: . Last updated: .

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)
 <ruby class=\"ruby88\">abc <rt>xyz</rt></ruby>

When called in lisp code, *begin *end are region begin/end positions.

URL `http://ergoemacs.org/emacs/elisp_html-ruby-annotation-markup.html'
Version 2017-01-11"
    (if (null @begin)
          (if (use-region-p)
                (setq @begin (region-beginning))
                (setq @end (region-end)))
              (setq @begin (line-beginning-position))
              (setq @end (line-end-position)))))
        (setq @begin (line-beginning-position))
        (setq @end (line-end-position))))
      (narrow-to-region @begin @end)
        (goto-char (point-min))
        (while (search-forward "(" nil "NOERROR")
          (replace-match "<rt>")))
        (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>"))))

in Emacs: Xah HTML Mode

see also HTML “ruby” Annotation Example

Elisp HTML Commands

  1. wrap-url
  2. URL to Link
  3. Link to Dead Link
  4. Make Image Links
  5. Extract URL
  6. Word to Wikipedia Linkify
  7. Wikipedia URL Linkify
  8. URL Percent Decode/Encode
  9. Lines to HTML Table
  10. Markup Function Names
  11. Color Source Code
  12. Transform Text Under Cursor
  13. Chinese Char Reference Linkify
  14. HTML make-citation
  15. update-title
  16. Google Map Linkify 🌐
  17. CSS Compressor
  18. Make Ruby Annotation
  19. Move Image File

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp