Skip to content

Commit db9be75

Browse files
benniekissjgm
authored andcommitted
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.
1 parent e8ed40e commit db9be75

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/Text/Pandoc/Parsing/Math.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mathInlineWith op cl = try $ do
4242
(try (string "text" >>
4343
(("\\text" <>) <$> inBalancedBraces 0 ""))
4444
<|> (\c -> T.pack ['\\',c]) <$> anyChar))
45-
<|> ("\n" <$ blankline <* notFollowedBy' blankline)
45+
<|> ("\n" <$ blankline <* notFollowedBy' blankline <* notFollowedBy (char '$'))
4646
<|> (T.pack <$> many1 spaceChar <* notFollowedBy (char '$'))
4747
) (try $ textStr cl)
4848
notFollowedBy digit -- to prevent capture of $5

test/command/11348.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
```
2+
% pandoc -f markdown -t native
3+
$ invalid opening inline math$
4+
5+
$
6+
invalid opening inline math$
7+
8+
$invalid closing inline math $
9+
10+
$invalid closing inline math
11+
$
12+
13+
$valid inline math$
14+
^D
15+
[ Para
16+
[ Str "$"
17+
, Space
18+
, Str "invalid"
19+
, Space
20+
, Str "opening"
21+
, Space
22+
, Str "inline"
23+
, Space
24+
, Str "math$"
25+
]
26+
, Para
27+
[ Str "$"
28+
, SoftBreak
29+
, Str "invalid"
30+
, Space
31+
, Str "opening"
32+
, Space
33+
, Str "inline"
34+
, Space
35+
, Str "math$"
36+
]
37+
, Para
38+
[ Str "$invalid"
39+
, Space
40+
, Str "closing"
41+
, Space
42+
, Str "inline"
43+
, Space
44+
, Str "math"
45+
, Space
46+
, Str "$"
47+
]
48+
, Para
49+
[ Str "$invalid"
50+
, Space
51+
, Str "closing"
52+
, Space
53+
, Str "inline"
54+
, Space
55+
, Str "math"
56+
, SoftBreak
57+
, Str "$"
58+
]
59+
, Para [ Math InlineMath "valid inline math" ]
60+
]
61+
```

0 commit comments

Comments
 (0)