]> git.eshelyaron.com Git - emacs.git/commitdiff
shr.el: Define rendering rule for math tag
authorAugusto Stoffel <arstoffel@gmail.com>
Sat, 12 Oct 2024 14:20:47 +0000 (16:20 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 1 Nov 2024 13:20:35 +0000 (14:20 +0100)
* lisp/net/shr.el (shr-tag-math): New function, see bug#73641.

(cherry picked from commit 9c5b6e88e7f851e239721a0fd855fbcd10b5b0a3)

lisp/net/shr.el

index f1062acf7e426aba951816eaf78eabb863a8453f..0c37ef67bbbbfa203dc87f7dcca3ba3514f2a2b2 100644 (file)
@@ -2264,6 +2264,18 @@ BASE is the URL of the HTML being rendered."
   (shr-generic dom)
   (insert ?\N{POP DIRECTIONAL ISOLATE}))
 
+(defun shr-tag-math (dom)
+  ;; Sometimes a math element contains a plain text annotation
+  ;; (typically TeX notation) in addition to MathML markup.  If we pass
+  ;; that to `dom-generic', the formula is printed twice.  So we select
+  ;; only the annotation if available.
+  (shr-generic
+   (thread-first
+     dom
+     (dom-child-by-tag 'semantics)
+     (dom-child-by-tag 'annotation)
+     (or dom))))
+
 ;;; Outline Support
 (defun shr-outline-search (&optional bound move backward looking-at)
   "A function that can be used as `outline-search-function' for rendered html.