diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2014-07-30 00:56:04 +0100 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2014-07-31 21:39:50 +0100 |
commit | 51051e9953f97c35178eded5d3959394a184baf4 (patch) | |
tree | a8ef04a3f5a6a632783077a5f0124c1d0fb732b9 /src | |
parent | 7c1f8673972eac79bfbccced0406a8fa4b3a319b (diff) | |
download | pandoc-51051e9953f97c35178eded5d3959394a184baf4.tar.gz |
HTML Reader: Added ability to read MathML formatted <math> blocks
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 34aa381d2..2e8b56124 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -571,6 +571,22 @@ pRawHtmlInline = do then return $ B.rawInline "html" $ renderTags' [result] else return mempty +mathMLToTeXMath :: String -> Either String String +mathMLToTeXMath s = writeTeXMath <$> readMathML s + +pMath :: Bool -> TagParser Inlines +pMath inCase = try $ do + open@(TagOpen _ attr) <- pSatisfy $ tagOpen (=="math") (const True) + unless (inCase) (guard (maybe False (== mathMLNamespace) (lookup "xmlns" attr))) + contents <- manyTill pAnyTag (pSatisfy (~== TagClose "math")) + let math = mathMLToTeXMath $ + (renderTags $ [open] ++ contents ++ [TagClose "math"]) + let constructor = + maybe B.math (\x -> if (x == "inline") then B.math else B.displayMath) + (lookup "display" attr) + return $ either (const mempty) + (\x -> if null x then mempty else constructor x) math + pInlinesInTags :: String -> (Inlines -> Inlines) -> TagParser Inlines pInlinesInTags tagtype f = extractSpaces f <$> pInTags tagtype inline |