From 019f5d1c9d31cbfeccc85648e9263b923980a580 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 15 Oct 2024 11:52:32 -0700 Subject: [PATCH] RST reader: fix linked substitutions. E.g. `|Python|_`. Closes #6588. --- src/Text/Pandoc/Readers/RST.hs | 12 +++++++++--- test/command/6588.md | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/command/6588.md diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 1860b14fe507..c2a4f098ac99 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -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 @@ -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 diff --git a/test/command/6588.md b/test/command/6588.md new file mode 100644 index 000000000000..efd3a68512b8 --- /dev/null +++ b/test/command/6588.md @@ -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 +

I recommend you try Python, +the best language around.

+```