Skip to content

Commit

Permalink
RST reader: fix linked substitutions.
Browse files Browse the repository at this point in the history
E.g. `|Python|_`.

Closes #6588.
  • Loading branch information
jgm committed Oct 15, 2024
1 parent 300e18e commit 019f5d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ resolveReferences x@(Link _ ils (s,_))
return $ Note (B.toList contents)
| Just ref <- T.stripPrefix "##SUBST##" s = do
substTable <- stateSubstitutions <$> getState
let key = toKey $ stripFirstAndLast ref
let key@(Key key') = toKey $ stripFirstAndLast ref
case M.lookup key substTable of
Nothing -> do
pos <- getPosition
logMessage $ ReferenceNotFound (tshow key) pos
logMessage $ ReferenceNotFound (tshow key') pos
return x
Just target -> case
B.toList target of
Expand Down Expand Up @@ -1711,7 +1711,13 @@ autoLink = autoURI <|> autoEmail
subst :: PandocMonad m => RSTParser m Inlines
subst = try $ do
(_,ref) <- withRaw $ enclosed (char '|') (char '|') inline
pure $ B.linkWith nullAttr ("##SUBST##" <> ref) "" (B.text ref)
let substlink = B.linkWith nullAttr ("##SUBST##" <> ref) "" (B.text ref)
reflink <- option False (True <$ char '_')
if reflink
then do
let linkref = T.drop 1 $ T.dropEnd 1 ref
return $ B.linkWith nullAttr ("##REF##" <> linkref) "" substlink
else return substlink

note :: PandocMonad m => RSTParser m Inlines
note = try $ do
Expand Down
10 changes: 10 additions & 0 deletions test/command/6588.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```
% pandoc -f rst
I recommend you try |Python|_.
.. |Python| replace:: Python, *the* best language around
.. _Python: http://www.python.org/
^D
<p>I recommend you try <a href="http://www.python.org/"><span>Python,
<em>the</em> best language around</span></a>.</p>
```

0 comments on commit 019f5d1

Please sign in to comment.