Elisp: Word to Wikipedia HTML Link

By Xah Lee. Date: . Last updated: .

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:
 Emacs
becomes
 <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 2021-05-18"
  (interactive)
  (let (($p0 (point)) $p1 $p2 $input $linkText)
    (if (region-active-p)
        (setq $p1 (region-beginning) $p2 (region-end))
      (progn
        (skip-chars-backward "^ \t\n")
        (setq $p1 (point))
        (goto-char $p0)
        (skip-chars-forward "^ \t\n")
        (setq $p2 (point))))
    (setq $input (buffer-substring-no-properties $p1 $p2))
    (setq $linkText (replace-regexp-in-string "_" " " $input))
    (delete-region $p1 $p2)
    (insert
     (format "<a href=\"http://en.wikipedia.org/wiki/%s\">%s</a>" (replace-regexp-in-string " " "_" $linkText) $linkText ))))

in Emacs: Xah HTML Mode

HTML

Tags

Links

CSS

Misc

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial