Don't treat a citation as a reference link label.

Closes #1763.
This commit is contained in:
John MacFarlane 2014-12-15 10:50:10 -08:00
parent 9bf76fa5a2
commit a5cac0a0c4
4 changed files with 16 additions and 4 deletions

4
README
View file

@ -2400,7 +2400,9 @@ The link consists of link text in square brackets, followed by a label in
square brackets. (There can be space between the two.) The link definition square brackets. (There can be space between the two.) The link definition
consists of the bracketed label, followed by a colon and a space, followed by consists of the bracketed label, followed by a colon and a space, followed by
the URL, and optionally (after a space) a link title either in quotes or in the URL, and optionally (after a space) a link title either in quotes or in
parentheses. parentheses. The label must not be parseable as a citation (assuming
the `citations` extension is enabled): citations take precedence over
link labels.
Here are some examples: Here are some examples:

View file

@ -1675,9 +1675,10 @@ referenceLink :: (String -> String -> Inlines -> Inlines)
-> (F Inlines, String) -> MarkdownParser (F Inlines) -> (F Inlines, String) -> MarkdownParser (F Inlines)
referenceLink constructor (lab, raw) = do referenceLink constructor (lab, raw) = do
sp <- (True <$ lookAhead (char ' ')) <|> return False sp <- (True <$ lookAhead (char ' ')) <|> return False
(ref,raw') <- try (ref,raw') <- option (mempty, "") $
(skipSpaces >> optional (newline >> skipSpaces) >> reference) lookAhead (try (spnl >> normalCite >> return (mempty, "")))
<|> return (mempty, "") <|>
try (spnl >> reference)
let labIsRef = raw' == "" || raw' == "[]" let labIsRef = raw' == "" || raw' == "[]"
let key = toKey $ if labIsRef then raw else raw' let key = toKey $ if labIsRef then raw else raw'
parsedRaw <- parseFromString (mconcat <$> many inline) raw' parsedRaw <- parseFromString (mconcat <$> many inline) raw'

View file

@ -152,6 +152,8 @@
,Para [Link [Str "linky"] ("hi_(there_(nested))","")] ,Para [Link [Str "linky"] ("hi_(there_(nested))","")]
,Header 2 ("reference-link-fallbacks",[],[]) [Str "Reference",Space,Str "link",Space,Str "fallbacks"] ,Header 2 ("reference-link-fallbacks",[],[]) [Str "Reference",Space,Str "link",Space,Str "fallbacks"]
,Para [Str "[",Emph [Str "not",Space,Str "a",Space,Str "link"],Str "]",Space,Str "[",Emph [Str "nope"],Str "]\8230"] ,Para [Str "[",Emph [Str "not",Space,Str "a",Space,Str "link"],Str "]",Space,Str "[",Emph [Str "nope"],Str "]\8230"]
,Header 2 ("reference-link-followed-by-a-citation",[],[]) [Str "Reference",Space,Str "link",Space,Str "followed",Space,Str "by",Space,Str "a",Space,Str "citation"]
,Para [Str "MapReduce",Space,Str "is",Space,Str "a",Space,Str "paradigm",Space,Str "popularized",Space,Str "by",Space,Link [Str "Google"] ("http://google.com",""),Space,Cite [Citation {citationId = "mapreduce", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@mapreduce]"],Space,Str "as",Space,Str "its",Space,Str "most",Space,Str "vocal",Space,Str "proponent."]
,Header 2 ("empty-reference-links",[],[]) [Str "Empty",Space,Str "reference",Space,Str "links"] ,Header 2 ("empty-reference-links",[],[]) [Str "Empty",Space,Str "reference",Space,Str "links"]
,Para [Str "bar"] ,Para [Str "bar"]
,Para [Link [Str "foo2"] ("","")]] ,Para [Link [Str "foo2"] ("","")]]

View file

@ -262,6 +262,13 @@ Empty cells
[*not a link*] [*nope*]... [*not a link*] [*nope*]...
## Reference link followed by a citation
MapReduce is a paradigm popularized by [Google] [@mapreduce] as its
most vocal proponent.
[Google]: http://google.com
## Empty reference links ## Empty reference links
[foo2]: [foo2]: