From 6f3ec91a0d64f90e955c51fbcff9f3a7f639f62c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 23 Oct 2023 19:38:58 -0700 Subject: CommonMark reader: handle `Ext_tex_math_gfm`. Parse GFM-specific math constructions when `tex_math_gfm` enabled. See . Closes #9121. --- src/Text/Pandoc/Readers/CommonMark.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index ad71e5c82..08f37830e 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -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) <$> @@ -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) -- cgit v1.2.3