RST reader: fix hyperlink aliases.

`link <google_>`_

    .. _google: https://google.com

is really a reference link.

Closes #3283.
This commit is contained in:
John MacFarlane 2016-12-07 12:54:25 +01:00
parent 97274c9991
commit 7fbfcb03d8
3 changed files with 13 additions and 2 deletions

View file

@ -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

View file

@ -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 "."]

View file

@ -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/>`_.