Skip to content

Commit

Permalink
CommonMark reader: handle Ext_tex_math_gfm.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Oct 24, 2023
1 parent d200cac commit 6f3ec91
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Text/Pandoc/Readers/CommonMark.hs
Expand Up @@ -100,6 +100,9 @@ readCommonMarkBody opts s toks =
(if isEnabled Ext_implicit_figures opts
then walk makeFigures
else id) .
(if isEnabled Ext_tex_math_gfm opts
then walk handleGfmMath
else id) .
(if readerStripComments opts
then walk stripBlockComments . walk stripInlineComments
else id) <$>
Expand All @@ -111,6 +114,21 @@ readCommonMarkBody opts s toks =
Left err -> throwError $ fromParsecError s err
Right (Cm bls :: Cm () Blocks) -> return $ B.doc bls

handleGfmMath :: Block -> Block
handleGfmMath (CodeBlock ("",["math"],[]) raw) = Para [Math DisplayMath raw]
handleGfmMath x = walk handleGfmMathInline x

handleGfmMathInline :: Inline -> Inline
handleGfmMathInline (Math InlineMath math') =
let (ticks, rest) = T.span (== '`') math'
in if T.null ticks
then Math InlineMath math'
else case T.stripSuffix ticks rest of
Just middle | not (T.null middle) && (T.last middle /= '`')
-> Math InlineMath middle
_ -> Math InlineMath math'
handleGfmMathInline x = x

stripBlockComments :: Block -> Block
stripBlockComments (RawBlock (B.Format "html") s) =
RawBlock (B.Format "html") (removeComments s)
Expand Down

0 comments on commit 6f3ec91

Please sign in to comment.