Elisp: Word to Wikipedia HTML Link

By Xah Lee. Date:

Here's a command to turn a word or phrase into a HTML link to Wikipedia.

(defun xah-html-word-to-wikipedia-linkify ()
  "Make the current word or text selection into a Wikipedia link.
For Example:
 <a href=\"http://en.wikipedia.org/wiki/Emacs\">Emacs</a>

URL `http://ergoemacs.org/emacs/elisp_html_word_to_wikipedia_linkify.html'
Version 2015-07-27"
  (let ($p0 $p1 $p2 $linkText)
    (if (region-active-p)
          (setq $p1 (region-beginning))
          (setq $p2 (region-end)))
        (setq $p0 (point))
        (skip-chars-backward "^ \t\n")
        (setq $p1 (point))
        (goto-char $p0)
        (skip-chars-forward "^ \t\n")
        (setq $p2 (point))))
    (setq $linkText
          (replace-regexp-in-string "_" " " (buffer-substring-no-properties $p1 $p2)))
    (delete-region $p1 $p2)
    (insert (concat "<a href=\"http://en.wikipedia.org/wiki/"
                    (replace-regexp-in-string " " "_" $linkText)
                    "\">" $linkText "</a>"))))

in Emacs: Xah HTML Mode

See also: Elisp: Wikipedia URL Linkify.

Elisp HTML Commands

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