From 11cf6f652baa2cb2d3495e06325b02db0cc77a11 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Wed, 28 Jan 2026 16:39:23 +0100 Subject: [PATCH] add xah html encode and decode * bba.org: xah-html-encode-ampersand-entity and xah-html-decode-ampersand-entity from http://xahlee.info/emacs/emacs/elisp_replace_html_entities_command.html --- bba.org | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/bba.org b/bba.org index 286c99d5..1bd59bdf 100644 --- a/bba.org +++ b/bba.org @@ -587,6 +587,69 @@ search the web on your fingertips. C-c /. (setq xah-lookup-browser-function 'eww) ) #+END_SRC + +* xah-html-decode +[2026-01-28 Wed 16:35] + +#+begin_src emacs-lisp + (defun xah-html-encode-ampersand-entity (&optional Begin End) + "Replace HTML chars & < > \" to & < > " on current block or selection. + + URL `http://xahlee.info/emacs/emacs/elisp_replace_html_entities_command.html' + Created: 2020-08-30 + Version: 2025-08-11" + (interactive) + (let (xbeg xend) + (seq-setq + (xbeg xend) + (if (and Begin End) + (list Begin End) + (if (region-active-p) + (list (region-beginning) (region-end)) + (list (save-excursion + (if (re-search-backward "\n[ \t]*\n" nil 1) + (match-end 0) + (point))) + (save-excursion + (if (re-search-forward "\n[ \t]*\n" nil 1) + (match-beginning 0) + (point))))))) + (save-restriction + (narrow-to-region xbeg xend) + (progn + (goto-char (point-min)) + (while (re-search-forward "&\\|<\\|>\\|\"" nil t) + (cond + ((string-equal "&" (match-string 0)) (replace-match "&" t t)) + ((string-equal "<" (match-string 0)) (replace-match "<" t t)) + ((string-equal ">" (match-string 0)) (replace-match ">" t t)) + ((string-equal "\"" (match-string 0)) (replace-match """ t t))) + (overlay-put (make-overlay (match-beginning 0) (match-end 0)) 'face 'highlight)))))) + + + (defun xah-html-decode-ampersand-entity (&optional Begin End) + "Replace & < > " to & < > ' on current block or selection. + + URL `http://xahlee.info/emacs/emacs/elisp_replace_html_entities_command.html' + Created: 2020-08-30 + Version: 2025-08-11" + (interactive) + (let (xbeg xend) + (seq-setq (xbeg xend) (if (and Begin End) (list Begin End) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point))))))) + + (save-restriction + (narrow-to-region xbeg xend) + (progn + (goto-char (point-min)) + (while (re-search-forward "&\\|<\\|>\\|"" nil t) + (cond + ((string-equal "&" (match-string 0)) (replace-match "&" t t)) + ((string-equal "<" (match-string 0)) (replace-match "<" t t)) + ((string-equal ">" (match-string 0)) (replace-match ">" t t)) + ((string-equal """ (match-string 0)) (replace-match "\"" t t))) + (overlay-put (make-overlay (match-beginning 0) (match-end 0)) 'face 'highlight)))))) +#+end_src + * expand-region [2015-04-02 Thu 10:32] -- 2.47.3