aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-10-15 11:07:20 -0700
committerJohn MacFarlane <[email protected]>2024-10-15 11:07:20 -0700
commite9e1684c9ede8aeef4f7b4be5403b5de4603781b (patch)
tree3923aecf60a05613db1766cfc184a2f57573ff5d /src
parentd39994375924a29fc8c518acc9fee7a936f14a31 (diff)
RST reader: explicit links define references.
For example, ``Go to `g`_ `g <www.example.com>`_.`` should produce two links to www.example.com. Closes #5081.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 879604e3f..f6203476f 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -30,7 +30,7 @@ import qualified Data.Text as T
import Text.Printf (printf)
import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines)
import qualified Text.Pandoc.Builder as B
-import Text.Pandoc.Class.PandocMonad (PandocMonad, fetchItem, getTimestamp)
+import Text.Pandoc.Class (PandocMonad, fetchItem, getTimestamp)
import Text.Pandoc.CSV (CSVOptions (..), defaultCSVOptions, parseCSV)
import Text.Pandoc.Definition
import Text.Pandoc.Error
@@ -1626,24 +1626,28 @@ explicitLink = try $ do
char '`'
notFollowedBy (char '`') -- `` marks start of inline code
label' <- trimInlines . mconcat <$>
- manyTill (notFollowedBy (char '`') >> inlineContent) (char '<')
+ manyTill (notFollowedBy (char '`') >> inlineContent) (char '<')
src <- trim . T.pack . filter (/= '\n') <$> -- see #10279
manyTill (noneOf ">\n" <|> (char '\n' <* notFollowedBy blankline))
(char '>')
skipSpaces
string "`_"
optional $ char '_' -- anonymous form
- let label'' = if label' == mempty
- then B.str src
- else label'
- -- `link <google_>` is a reference link to _google!
((src',tit),attr) <-
if isURI src
then return ((src, ""), nullAttr)
else
case T.unsnoc src of
+ -- `link <google_>` is a reference link to _google!
Just (xs, '_') -> lookupKey [] (toKey xs)
_ -> return ((src, ""), nullAttr)
+ let label'' = if label' == mempty
+ then B.str src
+ else label'
+ let key = toKey $ stringify label'
+ unless (key == Key mempty) $ do
+ updateState $ \s -> s{
+ stateKeys = M.insert key ((src',tit), attr) $ stateKeys s }
return $ B.linkWith attr (escapeURI src') tit label''
citationName :: PandocMonad m => RSTParser m Text