Skip to content

Commit

Permalink
Store a function instead of a Boolean
Browse files Browse the repository at this point in the history
Instead of storing isDisplay and then always choosing displayMath or math
based on that, just store displayMath or math directly.
  • Loading branch information
josephcsible authored and jgm committed Dec 15, 2024
1 parent a63cf06 commit 9bb67d6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Text/Pandoc/Readers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -927,25 +927,21 @@ pMath inCase = try $ do
let attr = toStringAttr attr'
unless inCase $
guard (maybe True (== mathMLNamespace) (lookup "xmlns" attr))
let isDisplay = case lookup "display" attr of
Just "block" -> True
_ -> False
let constructor = case lookup "display" attr of
Just "block" -> B.displayMath
_ -> B.math
contents <- manyTill pAny (pSatisfy (matchTagClose "math"))
-- KaTeX and others include original TeX in annotation tag;
-- just use this if present rather than parsing MathML:
case extractTeXAnnotation contents of
Just x -> return $ if isDisplay
then B.displayMath x
else B.math x
Just x -> return $ constructor x
Nothing ->
case mathMLToTeXMath (renderTags $
[open] <> contents <> [TagClose "math"]) of
Left _ -> return $ B.spanWith ("",["math"],attr) $ B.text $
innerText contents
Right "" -> return mempty
Right x -> return $ if isDisplay
then B.displayMath x
else B.math x
Right x -> return $ constructor x

extractTeXAnnotation :: [Tag Text] -> Maybe Text
extractTeXAnnotation [] = Nothing
Expand Down

0 comments on commit 9bb67d6

Please sign in to comment.