Markdown reader: fix parsing of inline math ($...$) (#11348)

Do not allow blank lines before closing `$` delimiter.
This brings the parser in line with the documentation.

Closes #11311.
This commit is contained in:
benniekiss
2025-12-14 10:44:56 -05:00
committed by John MacFarlane
parent e8ed40ef01
commit db9be758bc
2 changed files with 62 additions and 1 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ mathInlineWith op cl = try $ do
(try (string "text" >>
(("\\text" <>) <$> inBalancedBraces 0 ""))
<|> (\c -> T.pack ['\\',c]) <$> anyChar))
<|> ("\n" <$ blankline <* notFollowedBy' blankline)
<|> ("\n" <$ blankline <* notFollowedBy' blankline <* notFollowedBy (char '$'))
<|> (T.pack <$> many1 spaceChar <* notFollowedBy (char '$'))
) (try $ textStr cl)
notFollowedBy digit -- to prevent capture of $5
+61
View File
@@ -0,0 +1,61 @@
```
% pandoc -f markdown -t native
$ invalid opening inline math$
$
invalid opening inline math$
$invalid closing inline math $
$invalid closing inline math
$
$valid inline math$
^D
[ Para
[ Str "$"
, Space
, Str "invalid"
, Space
, Str "opening"
, Space
, Str "inline"
, Space
, Str "math$"
]
, Para
[ Str "$"
, SoftBreak
, Str "invalid"
, Space
, Str "opening"
, Space
, Str "inline"
, Space
, Str "math$"
]
, Para
[ Str "$invalid"
, Space
, Str "closing"
, Space
, Str "inline"
, Space
, Str "math"
, Space
, Str "$"
]
, Para
[ Str "$invalid"
, Space
, Str "closing"
, Space
, Str "inline"
, Space
, Str "math"
, SoftBreak
, Str "$"
]
, Para [ Math InlineMath "valid inline math" ]
]
```