git.iko.soy/typeable/pandoc
on master help sign in
RST reader: fix hyperlink aliases.

`link <google_>`_ .. _google: https://google.com is really a reference link. Closes #3283.

commit7fbfcb03d87feb369dcfabc1066e8f570ed471c8 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 7 Dec 2016, 12:54 (10 years ago) parent97274c9
3 files changed+13−2
src/Text/Pandoc/Readers/RST.hs+10−2 tests/rst-reader.native+1 tests/rst-reader.rst+2
src/Text/Pandoc/Readers/RST.hs+10−2
@@ -1120,14 +1120,22 @@ explicitLink = try $ do
11201120 notFollowedBy (char '`') -- `` marks start of inline code
11211121 label' <- trimInlines . mconcat <$>
11221122 manyTill (notFollowedBy (char '`') >> inline) (char '<')
1123− src <- manyTill (noneOf ">\n") (char '>')
1123+ src <- trim <$> manyTill (noneOf ">\n") (char '>')
11241124 skipSpaces
11251125 string "`_"
11261126 optional $ char '_' -- anonymous form
11271127 let label'' = if label' == mempty
11281128 then B.str src
11291129 else label'
1130− return $ B.link (escapeURI $ trim src) "" label''
1130+ -- `link <google_>` is a reference link to _google!
1131+ (src',tit,attr) <- case reverse src of
1132+ '_':xs -> do
1133+ keyTable <- stateKeys <$> getState
1134+ case M.lookup (toKey (reverse xs)) keyTable of
1135+ Nothing -> fail "no corresponding key"
1136+ Just ((s,t),a) -> return (s,t,a)
1137+ _ -> return (src, "", nullAttr)
1138+ return $ B.linkWith attr (escapeURI src') tit label''
11311139
11321140referenceLink :: RSTParser Inlines
11331141referenceLink = try $ do
tests/rst-reader.native+1
@@ -214,6 +214,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
214214,Para [Str "Explicit",Space,Str "with",Space,Str "no",Space,Str "label:",Space,Link ("",[],[]) [Str "foo"] ("foo",""),Str "."]
215215,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/","")]
216216,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."]
217+,Para [Str "Another",Space,Link ("",[],[]) [Str "style",Space,Str "of",Space,Str "reference",Space,Str "link"] ("/url1/",""),Str "."]
217218,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 "."]
218219,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 "."]
219220,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 "."]
tests/rst-reader.rst+2
@@ -390,6 +390,8 @@ Reference links: `link1`_ and `link2`_ and link1_ again.
390390.. _link1: /url1/
391391.. _`link2`: /url2/
392392
393+Another `style of reference link <link1_>`_.
394+
393395Here's a `link with an ampersand in the URL`_.
394396
395397Here's a link with an amersand in the link text: `AT&T </url/>`_.