Skip to content

Commit

Permalink
Small improvement to math parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Feb 28, 2022
1 parent 15e0995 commit cc815e0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions commonmark-extensions/src/Commonmark/Extensions/Math.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ parseMath :: (Monad m, HasMath a) => InlineParser m a
parseMath = try $ do
symbol '$'
display <- (True <$ symbol '$') <|> (False <$ notFollowedBy whitespace)
(do contents <- try $ untokenize <$> pDollarsMath 0
if display
then displayMath contents <$ symbol '$'
else if T.all (==' ') (T.takeEnd 1 contents)
-- don't allow math to end with SPACE + $
then mzero
else return $ inlineMath contents)
<|> (guard display >> return (inlineMath ""))
contents <- try $ untokenize <$> pDollarsMath 0
if display
then displayMath contents <$ symbol '$'
else if T.all (==' ') (T.takeEnd 1 contents)
-- don't allow math to end with SPACE + $
then mzero
else return $ inlineMath contents

-- Int is number of embedded groupings
pDollarsMath :: Monad m => Int -> InlineParser m [Tok]
Expand Down

0 comments on commit cc815e0

Please sign in to comment.