From bdda4b185bdab5e4eb56a1ce422f4efebdb5ace9 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 2 Nov 2016 16:14:25 +0100 Subject: HTML reader: treat `` as MathML by default... unless something else is explicitly specified in xmlns. Provided it parses as MathML, of course. Also fixed default which should be to inline math if no display attribute is used. --- src/Text/Pandoc/Readers/HTML.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 8ce3fa379..10a2976e5 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -666,15 +666,18 @@ mathMLToTeXMath s = writeTeX <$> 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))) + -- we'll assume math tags are MathML unless specially marked + -- otherwise... + unless inCase $ + guard (maybe True (== 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 + case mathMLToTeXMath (renderTags $ [open] ++ contents ++ [TagClose "math"]) of + Left _ -> return $ B.spanWith ("",["math"],attr) $ B.text $ + innerText contents + Right [] -> return mempty + Right x -> return $ case lookup "display" attr of + Just "block" -> B.displayMath x + _ -> B.math x pInlinesInTags :: String -> (Inlines -> Inlines) -> TagParser Inlines -- cgit v1.2.3