Skip to content

Commit 9fa4fa3

Browse files
committedDec 28, 2024·
RST reader: fix handling of underscores.
Fixes a regression in 3.6 that caused problems parsing text with underscores. Closes #10497.
1 parent 07105cc commit 9fa4fa3

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed
 

‎src/Text/Pandoc/Readers/RST.hs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ substKey = try $ do
12861286
anonymousKey :: PandocMonad m => RSTParser m ()
12871287
anonymousKey = try $ do
12881288
oneOfStrings [".. __:", "__"]
1289+
skipMany1 spaceChar
12891290
src <- targetURI
12901291
-- we need to ensure that the keys are ordered by occurrence in
12911292
-- the document.
@@ -1462,15 +1463,14 @@ table = gridTable <|> simpleTable False <|> simpleTable True <?> "table"
14621463
--
14631464

14641465
inline :: PandocMonad m => RSTParser m Inlines
1465-
inline = choice [ note -- can start with whitespace, so try before ws
1466-
, link
1467-
, inlineAnchor
1468-
, strong
1469-
, emph
1470-
, code
1471-
, subst
1472-
, interpretedRole
1473-
, inlineContent ] <?> "inline"
1466+
inline =
1467+
(note -- can start with whitespace, so try before ws
1468+
<|> do notAfterString >>= guard
1469+
(link <|> inlineAnchor <|> strong <|> emph)
1470+
<|> code
1471+
<|> subst
1472+
<|> interpretedRole
1473+
<|> inlineContent) <?> "inline"
14741474

14751475
-- strings, spaces and other characters that can appear either by
14761476
-- themselves or within inline markup
@@ -1730,6 +1730,7 @@ referenceLink :: PandocMonad m => RSTParser m Inlines
17301730
referenceLink = try $ do
17311731
ref <- (referenceName <|> citationName) <* char '_'
17321732
isAnonymous <- (True <$ char '_') <|> pure False
1733+
eof <|> notFollowedBy alphaNum
17331734
let ref' = if isAnonymous
17341735
then "_"
17351736
else ref
@@ -1797,7 +1798,7 @@ smart :: PandocMonad m => RSTParser m Inlines
17971798
smart = smartPunctuation inline
17981799

17991800
inlineAnchor :: PandocMonad m => RSTParser m Inlines
1800-
inlineAnchor = do
1801+
inlineAnchor = try $ do
18011802
char '_'
18021803
name <- quotedReferenceName <|> simpleReferenceName
18031804
let ident = textToIdentifier mempty name

‎test/command/10497.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
```
2+
% pandoc -f rst
3+
a.__b__
4+
5+
a__b__
6+
7+
__foo__
8+
^D
9+
<p>a.__b__</p>
10+
<p>a__b__</p>
11+
<p>__foo__</p>
12+
```
13+

0 commit comments

Comments
 (0)
Please sign in to comment.