Elisp: Chinese Character Reference Linkify

By Xah Lee. Date: . Last updated: .

We need a command to change the character under cursor into several HTML links.

For example, this


<div class="x23394">
<b class="w"></b>
<span class="en">
<a href="…">Translate</a> •
<a href="…">Wiktionary</a> •
<a href="…">history</a>

Appears in browser like this:

chinese char link 6a017

This is useful for writing blog on languages and linguistics.


Here's the code:

(defun xah-words-chinese-linkify ()
  "Make the Chinese character before cursor into Chinese dictionary reference links.
URL `http://ergoemacs.org/emacs/elisp_chinese_char_linkify.html'
Version 2019-06-17"
  (let (
         "<div class=\"chinese-etymology-96656\"><b class=\"w\">▮</b> <span class=\"en\"><a href=\"https://translate.google.com/#zh-CN|en|▮\">Translate</a> • <a href=\"https://en.wiktionary.org/wiki/▮\">Wiktionary</a> • <a href=\"https://hanziyuan.net/#▮\">history</a></span></div>"
        ($char (buffer-substring-no-properties (- (point) 1) (point))))
    (delete-char -1)
    (insert (replace-regexp-in-string "▮" $char $template))))

This is truely a time saver.

URL Encoding of Chinese

Note: technically, Chinese chars in a URL should be URL Encoded.

For example:


should be:


(A Chinese character should become bytes in hex from the char's UTF-8 encoding. The char 中's UTF-8 encoding is 3 bytes of the following hexadecimal: E4 B8 AD.)

However, i think the situation of percent encoding is a abomination. [see Problems of Symbol Congestion in Computer Languages; ASCII Jam vs Unicode] I decided to not botch my Chinese chars in URL. This does not cause practical problems.

If you want to do that, see: Elisp: URL Percent Decode/Encode

Emacs Chinese Topics

  1. Elisp: Chinese Character Reference Linkify
  2. Emacs: Convert Full-Width/Half-Width Punctuations
  3. Emacs Chinese Input

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