HTML reader: parse <script type="math/tex tags as math.

These are used by MathJax.

Closes #4877.
This commit is contained in:
John MacFarlane
2018-09-07 09:41:17 -07:00
parent 6397aacdae
commit a211edc819
2 changed files with 25 additions and 0 deletions
+12
View File
@@ -663,6 +663,7 @@ inline = choice
, pCode
, pSpan
, pMath False
, pScriptMath
, pRawHtmlInline
]
@@ -822,6 +823,17 @@ toStringAttr :: [(Text, Text)] -> [(String, String)]
toStringAttr = map go
where go (x,y) = (T.unpack x, T.unpack y)
pScriptMath :: PandocMonad m => TagParser m Inlines
pScriptMath = try $ do
TagOpen _ attr' <- pSatisfy $ tagOpen (=="script") (const True)
isdisplay <- case lookup "type" attr' of
Just x | "math/tex" `T.isPrefixOf` x
-> return $ "display" `T.isSuffixOf` x
_ -> mzero
contents <- T.unpack . innerText <$>
manyTill pAnyTag (pSatisfy (matchTagClose "script"))
return $ (if isdisplay then B.displayMath else B.math) contents
pMath :: PandocMonad m => Bool -> TagParser m Inlines
pMath inCase = try $ do
open@(TagOpen _ attr') <- pSatisfy $ tagOpen (=="math") (const True)
+13
View File
@@ -0,0 +1,13 @@
```
% pandoc -f html -t native
My <script type="math/tex">\mathcal{D}</script>
^D
[Plain [Str "My",Space,Math InlineMath "\\mathcal{D}"]]
```
```
% pandoc -f html -t native
<script type="math/tex; mode=display">\mathcal{D}</script>
^D
[Plain [Math DisplayMath "\\mathcal{D}"]]
```