Emacs: Replace HTML Entities 🚀
Escape HTML Chars to Entities
Here's a command to replace AMPERSAND, LESS-THAN SIGN, GREATER-THAN SIGN, to entities, or inverse.
(defun xah-html-encode-ampersand-entity (&optional Begin End Report-p Highlight-p) "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: 2024-03-19" (interactive (list nil nil t t)) (let (xbeg xend) (seq-setq (xbeg xend) (if (and Begin End) (vector Begin End) (xah-get-pos-of-block-or))) (message "Calling %s" this-command) (xah-replace-pairs-region xbeg xend [ ["&" "&"] ["<" "<"] [">" ">"] ] Report-p Highlight-p)))
(defun xah-html-decode-ampersand-entity (&optional Begin End Report-p Highlight-p) "Replace & < > to & < > on current block or selection. URL `http://xahlee.info/emacs/emacs/elisp_replace_html_entities_command.html' Created: 2020-08-30 Version: 2024-03-19" (interactive (list nil nil t t)) (let (xbeg xend) (seq-setq (xbeg xend) (if (and Begin End) (vector Begin End) (xah-get-pos-of-block-or))) (message "Calling %s" this-command) (xah-replace-pairs-region xbeg xend [ ["&" "&"] ["<" "<"] [">" ">"] ] Report-p Highlight-p)))
requires package:
Named Entities to Character
Replace HTML named entities to its Unicode character. 〔see HTML XML Entities List〕
(defun xah-html-named-entity-to-char (Begin End) "Replace named entity to Unicode character in current block or selection. Changed places are highlighted. For example, “©” becomes “©”. The following HTML Entities are not replaced: & < > When called in lisp code, Begin End are region begin/end positions. URL `http://xahlee.info/emacs/emacs/elisp_replace_html_entities_command.html' Created: 2020-08-30 Version: 2024-03-19" (interactive (seq-let (xbeg xend) (xah-get-pos-of-block-or) (list xbeg xend))) (let ((xreplaceMap [ [" " " "] [" " " "] [" " " "] [" " " "] ["‏" ""] ["‎" ""] ["‍" ""] ["‌" ""] ["¡" "¡"] ["¢" "¢"] ["£" "£"] ["¤" "¤"] ["¥" "¥"] ["¦" "¦"] ["§" "§"] ["¨" "¨"] ["©" "©"] ["ª" "ª"] ["«" "«"] ["¬" "¬"] ["­" ""] ["®" "®"] ["¯" "¯"] ["°" "°"] ["±" "±"] ["²" "²"] ["³" "³"] ["´" "´"] ["µ" "µ"] ["¶" "¶"] ["·" "·"] ["¸" "¸"] ["¹" "¹"] ["º" "º"] ["»" "»"] ["¼" "¼"] ["½" "½"] ["¾" "¾"] ["¿" "¿"] ["À" "À"] ["Á" "Á"] ["Â" "Â"] ["Ã" "Ã"] ["Ä" "Ä"] ["Å" "Å"] ["Æ" "Æ"] ["Ç" "Ç"] ["È" "È"] ["É" "É"] ["Ê" "Ê"] ["Ë" "Ë"] ["Ì" "Ì"] ["Í" "Í"] ["Î" "Î"] ["Ï" "Ï"] ["Ð" "Ð"] ["Ñ" "Ñ"] ["Ò" "Ò"] ["Ó" "Ó"] ["Ô" "Ô"] ["Õ" "Õ"] ["Ö" "Ö"] ["×" "×"] ["Ø" "Ø"] ["Ù" "Ù"] ["Ú" "Ú"] ["Û" "Û"] ["Ü" "Ü"] ["Ý" "Ý"] ["Þ" "Þ"] ["ß" "ß"] ["à" "à"] ["á" "á"] ["â" "â"] ["ã" "ã"] ["ä" "ä"] ["å" "å"] ["æ" "æ"] ["ç" "ç"] ["è" "è"] ["é" "é"] ["ê" "ê"] ["ë" "ë"] ["ì" "ì"] ["í" "í"] ["î" "î"] ["ï" "ï"] ["ð" "ð"] ["ñ" "ñ"] ["ò" "ò"] ["ó" "ó"] ["ô" "ô"] ["õ" "õ"] ["ö" "ö"] ["÷" "÷"] ["ø" "ø"] ["ù" "ù"] ["ú" "ú"] ["û" "û"] ["ü" "ü"] ["ý" "ý"] ["þ" "þ"] ["ÿ" "ÿ"] ["ƒ" "ƒ"] ["Α" "Α"] ["Β" "Β"] ["Γ" "Γ"] ["Δ" "Δ"] ["Ε" "Ε"] ["Ζ" "Ζ"] ["Η" "Η"] ["Θ" "Θ"] ["Ι" "Ι"] ["Κ" "Κ"] ["Λ" "Λ"] ["Μ" "Μ"] ["Ν" "Ν"] ["Ξ" "Ξ"] ["Ο" "Ο"] ["Π" "Π"] ["Ρ" "Ρ"] ["Σ" "Σ"] ["Τ" "Τ"] ["Υ" "Υ"] ["Φ" "Φ"] ["Χ" "Χ"] ["Ψ" "Ψ"] ["Ω" "Ω"] ["α" "α"] ["β" "β"] ["γ" "γ"] ["δ" "δ"] ["ε" "ε"] ["ζ" "ζ"] ["η" "η"] ["θ" "θ"] ["ι" "ι"] ["κ" "κ"] ["λ" "λ"] ["μ" "μ"] ["ν" "ν"] ["ξ" "ξ"] ["ο" "ο"] ["π" "π"] ["ρ" "ρ"] ["ς" "ς"] ["σ" "σ"] ["τ" "τ"] ["υ" "υ"] ["φ" "φ"] ["χ" "χ"] ["ψ" "ψ"] ["ω" "ω"] ["ϑ" "ϑ"] ["ϒ" "ϒ"] ["ϖ" "ϖ"] ["•" "•"] ["…" "…"] ["′" "′"] ["″" "″"] ["‾" "‾"] ["⁄" "⁄"] ["℘" "℘"] ["ℑ" "ℑ"] ["ℜ" "ℜ"] ["™" "™"] ["ℵ" "ℵ"] ["←" "←"] ["↑" "↑"] ["→" "→"] ["↓" "↓"] ["↔" "↔"] ["↵" "↵"] ["⇐" "⇐"] ["⇑" "⇑"] ["⇒" "⇒"] ["⇓" "⇓"] ["⇔" "⇔"] ["∀" "∀"] ["∂" "∂"] ["∃" "∃"] ["∅" "∅"] ["∇" "∇"] ["∈" "∈"] ["∉" "∉"] ["∋" "∋"] ["∏" "∏"] ["∑" "X"] ["−" "−"] ["∗" "∗"] ["√" "√"] ["∝" "∝"] ["∞" "∞"] ["∠" "∠"] ["∧" "∧"] ["∨" "∨"] ["∩" "∩"] ["∪" "∪"] ["∫" "∫"] ["∴" "∴"] ["∼" "∼"] ["≅" "≅"] ["≈" "≈"] ["≠" "≠"] ["≡" "≡"] ["≤" "≤"] ["≥" "≥"] ["⊂" "⊂"] ["⊃" "⊃"] ["⊄" "⊄"] ["⊆" "⊆"] ["⊇" "⊇"] ["⊕" "⊕"] ["⊗" "⊗"] ["⊥" "⊥"] ["⋅" "⋅"] ["⌈" "⌈"] ["⌉" "⌉"] ["⌊" "⌊"] ["⌋" "⌋"] ["⟨" "〈"] ["⟩" "〉"] ["◊" "◊"] ["♠" "♠"] ["♣" "♣"] ["♥" "♥"] ["♦" "♦"] [""" "\""] ["Œ" "Œ"] ["œ" "œ"] ["Š" "Š"] ["š" "š"] ["Ÿ" "Ÿ"] ["ˆ" "ˆ"] ["˜" "˜"] ["–" "–"] ["—" "—"] ["‘" "‘"] ["’" "’"] ["‚" "‚"] ["“" "“"] ["”" "”"] ["„" "„"] ["†" "†"] ["‡" "‡"] ["‰" "‰"] ["‹" "‹"] ["›" "›"] ["€" "€"] ])) (xah-replace-pairs-region Begin End xreplaceMap nil t)))
requires package: