git.iko.soy/typeable/pandoc
on master help sign in
RST reader: fix hyperlink aliases.
7fbfcb0John MacFarlane
src/Text/Pandoc/Readers/RST.hs+10−2
@@ -1120,14 +1120,22 @@ explicitLink = try $ do
1120 notFollowedBy (char '`') -- `` marks start of inline code
1120 notFollowedBy (char '`') -- `` marks start of inline code
1121 label' <- trimInlines . mconcat <$>
1121 label' <- trimInlines . mconcat <$>
1122 manyTill (notFollowedBy (char '`') >> inline) (char '<')
1122 manyTill (notFollowedBy (char '`') >> inline) (char '<')
1123− src <- manyTill (noneOf ">\n") (char '>')
1123+ src <- trim <$> manyTill (noneOf ">\n") (char '>')
1124 skipSpaces
1124 skipSpaces
1125 string "`_"
1125 string "`_"
1126 optional $ char '_' -- anonymous form
1126 optional $ char '_' -- anonymous form
1127 let label'' = if label' == mempty
1127 let label'' = if label' == mempty
1128 then B.str src
1128 then B.str src
1129 else label'
1129 else 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)
1130− return $ B.link (escapeURI $ trim src) "" label''
1138+ return $ B.linkWith attr (escapeURI src') tit label''
1131
1139
1132referenceLink :: RSTParser Inlines
1140referenceLink :: RSTParser Inlines
1133referenceLink = try $ do
1141referenceLink = try $ do
tests/rst-reader.native+1
@@ -214,6 +214,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
214,Para [Str "Explicit",Space,Str "with",Space,Str "no",Space,Str "label:",Space,Link ("",[],[]) [Str "foo"] ("foo",""),Str "."]
214,Para [Str "Explicit",Space,Str "with",Space,Str "no",Space,Str "label:",Space,Link ("",[],[]) [Str "foo"] ("foo",""),Str "."]
215,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/","")]
215,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/","")]
216,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."]
216,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 "."]
217,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 "."]
218,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 "."]
218,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 "."]
219,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 "."]
219,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 "."]
220,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.
390.. _link1: /url1/
390.. _link1: /url1/
391.. _`link2`: /url2/
391.. _`link2`: /url2/
392
392
393+Another `style of reference link <link1_>`_.
394+
393Here's a `link with an ampersand in the URL`_.
395Here's a `link with an ampersand in the URL`_.
394
396
395Here's a link with an amersand in the link text: `AT&T </url/>`_.
397Here's a link with an amersand in the link text: `AT&T </url/>`_.