Skip to content

Commit

Permalink
RST reader: support inline anchors.
Browse files Browse the repository at this point in the history
Closes #9196.
  • Loading branch information
jgm committed Oct 15, 2024
1 parent e9e1684 commit 300e18e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@ table = gridTable <|> simpleTable False <|> simpleTable True <?> "table"
inline :: PandocMonad m => RSTParser m Inlines
inline = choice [ note -- can start with whitespace, so try before ws
, link
, inlineAnchor
, strong
, emph
, code
Expand Down Expand Up @@ -1721,3 +1722,13 @@ note = try $ do

smart :: PandocMonad m => RSTParser m Inlines
smart = smartPunctuation inline

inlineAnchor :: PandocMonad m => RSTParser m Inlines
inlineAnchor = do
char '_'
name <- quotedReferenceName <|> simpleReferenceName
let ident = textToIdentifier mempty name
updateState $ \s ->
s{ stateKeys = M.insert (toKey name) (("#" <> ident, ""), nullAttr)
(stateKeys s) }
pure $ B.spanWith (ident,[],[]) (B.text name)
6 changes: 6 additions & 0 deletions test/command/9196.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
% pandoc -f rst --wrap=none
Define _`my target`, then reference `my target`_.
^D
<p>Define <span id="my-target">my target</span>, then reference <a href="#my-target">my target</a>.</p>
```

0 comments on commit 300e18e

Please sign in to comment.