diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-09-06 17:05:04 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-09-07 09:41:17 -0700 |
commit | a211edc8192f2abc9787c1012a3cf3cb3f96952c (patch) | |
tree | f03a95f0038e10fe55ede2fcceb6889c76566f20 /src | |
parent | 6397aacdaed3f5ca3305a383b8ff6575f5d73e5d (diff) | |
download | pandoc-a211edc8192f2abc9787c1012a3cf3cb3f96952c.tar.gz |
HTML reader: parse `<script type="math/tex` tags as math.
These are used by MathJax.
Closes #4877.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index ea62bfcbf..b06e07a80 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -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) |