diff --git a/commonmark-extensions/src/Commonmark/Extensions/Math.hs b/commonmark-extensions/src/Commonmark/Extensions/Math.hs index b2f5095..ad6dd0b 100644 --- a/commonmark-extensions/src/Commonmark/Extensions/Math.hs +++ b/commonmark-extensions/src/Commonmark/Extensions/Math.hs @@ -55,6 +55,7 @@ pDisplayMath = try $ do (_, toks) <- withRaw $ many1 $ choice [ () <$ symbol '\\' >> anyTok , noneOfToks [Symbol '$'] + , try (symbol '$' <* notFollowedBy (symbol '$')) ] count 2 $ symbol '$' return $! displayMath (untokenize toks) diff --git a/commonmark-extensions/test/math.md b/commonmark-extensions/test/math.md index 1547d1e..f88777d 100644 --- a/commonmark-extensions/test/math.md +++ b/commonmark-extensions/test/math.md @@ -37,6 +37,22 @@ e=mc^2 \]
```````````````````````````````` +Note that display math can contain embedded inline math: + +```````````````````````````````` example +This is display math: +$$ +\text{Hello $x^2$} +$$ +. +This is display math: +\[ +\text{Hello $x^2$} +\]
+```````````````````````````````` + + + To avoid treating currency signs as math delimiters, one may occasionally have to backslash-escape them: