aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/RST.hs12
-rw-r--r--tests/rst-reader.native1
-rw-r--r--tests/rst-reader.rst2
3 files changed, 13 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 1b06c6f23..e3d94d7b4 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -1120,14 +1120,22 @@ explicitLink = try $ do
notFollowedBy (char '`') -- `` marks start of inline code
label' <- trimInlines . mconcat <$>
manyTill (notFollowedBy (char '`') >> inline) (char '<')
- src <- manyTill (noneOf ">\n") (char '>')
+ src <- trim <$> manyTill (noneOf ">\n") (char '>')
skipSpaces
string "`_"
optional $ char '_' -- anonymous form
let label'' = if label' == mempty
then B.str src
else label'
- return $ B.link (escapeURI $ trim src) "" label''
+ -- `link <google_>` is a reference link to _google!
+ (src',tit,attr) <- case reverse src of
+ '_':xs -> do
+ keyTable <- stateKeys <$> getState
+ case M.lookup (toKey (reverse xs)) keyTable of
+ Nothing -> fail "no corresponding key"
+ Just ((s,t),a) -> return (s,t,a)
+ _ -> return (src, "", nullAttr)
+ return $ B.linkWith attr (escapeURI src') tit label''
referenceLink :: RSTParser Inlines
referenceLink = try $ do
diff --git a/tests/rst-reader.native b/tests/rst-reader.native
index 4a3df7f24..768a05c24 100644
--- a/tests/rst-reader.native
+++ b/tests/rst-reader.native
@@ -214,6 +214,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,Para [Str "Explicit",Space,Str "with",Space,Str "no",Space,Str "label:",Space,Link ("",[],[]) [Str "foo"] ("foo",""),Str "."]
,Para [Str "Two",Space,Str "anonymous",Space,Str "links:",Space,Link ("",[],[]) [Str "the",Space,Str "first"] ("/url1/",""),Space,Str "and",Space,Link ("",[],[]) [Str "the",Space,Str "second"] ("/url2/","")]
,Para [Str "Reference",Space,Str "links:",Space,Link ("",[],[]) [Str "link1"] ("/url1/",""),Space,Str "and",Space,Link ("",[],[]) [Str "link2"] ("/url2/",""),Space,Str "and",Space,Link ("",[],[]) [Str "link1"] ("/url1/",""),Space,Str "again."]
+,Para [Str "Another",Space,Link ("",[],[]) [Str "style",Space,Str "of",Space,Str "reference",Space,Str "link"] ("/url1/",""),Str "."]
,Para [Str "Here\8217s",Space,Str "a",Space,Link ("",[],[]) [Str "link",Space,Str "with",Space,Str "an",Space,Str "ampersand",Space,Str "in",Space,Str "the",Space,Str "URL"] ("http://example.com/?foo=1&bar=2",""),Str "."]
,Para [Str "Here\8217s",Space,Str "a",Space,Str "link",Space,Str "with",Space,Str "an",Space,Str "amersand",Space,Str "in",Space,Str "the",Space,Str "link",Space,Str "text:",Space,Link ("",[],[]) [Str "AT&T"] ("/url/",""),Str "."]
,Para [Str "Autolinks:",Space,Link ("",[],[]) [Str "http://example.com/?foo=1&bar=2"] ("http://example.com/?foo=1&bar=2",""),Space,Str "and",Space,Link ("",[],[]) [Str "nobody@nowhere.net"] ("mailto:nobody@nowhere.net",""),Str "."]
diff --git a/tests/rst-reader.rst b/tests/rst-reader.rst
index 450f2b939..cfe959f2d 100644
--- a/tests/rst-reader.rst
+++ b/tests/rst-reader.rst
@@ -390,6 +390,8 @@ Reference links: `link1`_ and `link2`_ and link1_ again.
.. _link1: /url1/
.. _`link2`: /url2/
+Another `style of reference link <link1_>`_.
+
Here's a `link with an ampersand in the URL`_.
Here's a link with an amersand in the link text: `AT&T </url/>`_.