RST reader: support inline anchors.

Closes #9196.
This commit is contained in:
John MacFarlane
2024-10-15 11:25:28 -07:00
parent e9e1684c9e
commit 300e18efba
2 changed files with 17 additions and 0 deletions
+11
View File
@@ -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
@@ -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
View File
@@ -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>
```