git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: parse `<script type="math/tex` tags as math.

These are used by MathJax. Closes #4877.

commita211edc8192f2abc9787c1012a3cf3cb3f96952c authorJohn MacFarlane <jgm@berkeley.edu> dateThu 6 Sep 2018, 17:05 (8 years ago) parent6397aac
2 files changed+25
src/Text/Pandoc/Readers/HTML.hs+12 test/command/4877.md+13
src/Text/Pandoc/Readers/HTML.hs+12
@@ -663,6 +663,7 @@ inline = choice
663663 , pCode
664664 , pSpan
665665 , pMath False
666+ , pScriptMath
666667 , pRawHtmlInline
667668 ]
668669
@@ -822,6 +823,17 @@ toStringAttr :: [(Text, Text)] -> [(String, String)]
822823toStringAttr = map go
823824 where go (x,y) = (T.unpack x, T.unpack y)
824825
826+pScriptMath :: PandocMonad m => TagParser m Inlines
827+pScriptMath = try $ do
828+ TagOpen _ attr' <- pSatisfy $ tagOpen (=="script") (const True)
829+ isdisplay <- case lookup "type" attr' of
830+ Just x | "math/tex" `T.isPrefixOf` x
831+ -> return $ "display" `T.isSuffixOf` x
832+ _ -> mzero
833+ contents <- T.unpack . innerText <$>
834+ manyTill pAnyTag (pSatisfy (matchTagClose "script"))
835+ return $ (if isdisplay then B.displayMath else B.math) contents
836+
825837pMath :: PandocMonad m => Bool -> TagParser m Inlines
826838pMath inCase = try $ do
827839 open@(TagOpen _ attr') <- pSatisfy $ tagOpen (=="math") (const True)
test/command/4877.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f html -t native
3+My <script type="math/tex">\mathcal{D}</script>
4+^D
5+[Plain [Str "My",Space,Math InlineMath "\\mathcal{D}"]]
6+```
7+
8+```
9+% pandoc -f html -t native
10+<script type="math/tex; mode=display">\mathcal{D}</script>
11+^D
12+[Plain [Math DisplayMath "\\mathcal{D}"]]
13+```