git.iko.soy/typeable/pandoc
on master help sign in
Don't treat a citation as a reference link label.

Closes #1763.

commita5cac0a0c401b0d5c901ac734c877f6a32bddb40 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 15 Dec 2014, 10:50 (12 years ago) parent9bf76fa
4 files changed+16−4
README+3−1 src/Text/Pandoc/Readers/Markdown.hs+4−3 tests/markdown-reader-more.native+2 tests/markdown-reader-more.txt+7
README+3−1
@@ -2400,7 +2400,9 @@ The link consists of link text in square brackets, followed by a label in
24002400square brackets. (There can be space between the two.) The link definition
24012401consists of the bracketed label, followed by a colon and a space, followed by
24022402the URL, and optionally (after a space) a link title either in quotes or in
2403−parentheses.
2403+parentheses. The label must not be parseable as a citation (assuming
2404+the `citations` extension is enabled): citations take precedence over
2405+link labels.
24042406
24052407Here are some examples:
24062408
src/Text/Pandoc/Readers/Markdown.hs+4−3
@@ -1675,9 +1675,10 @@ referenceLink :: (String -> String -> Inlines -> Inlines)
16751675 -> (F Inlines, String) -> MarkdownParser (F Inlines)
16761676referenceLink constructor (lab, raw) = do
16771677 sp <- (True <$ lookAhead (char ' ')) <|> return False
1678− (ref,raw') <- try
1679− (skipSpaces >> optional (newline >> skipSpaces) >> reference)
1680− <|> return (mempty, "")
1678+ (ref,raw') <- option (mempty, "") $
1679+ lookAhead (try (spnl >> normalCite >> return (mempty, "")))
1680+ <|>
1681+ try (spnl >> reference)
16811682 let labIsRef = raw' == "" || raw' == "[]"
16821683 let key = toKey $ if labIsRef then raw else raw'
16831684 parsedRaw <- parseFromString (mconcat <$> many inline) raw'
tests/markdown-reader-more.native+2
@@ -152,6 +152,8 @@
152152,Para [Link [Str "linky"] ("hi_(there_(nested))","")]
153153,Header 2 ("reference-link-fallbacks",[],[]) [Str "Reference",Space,Str "link",Space,Str "fallbacks"]
154154,Para [Str "[",Emph [Str "not",Space,Str "a",Space,Str "link"],Str "]",Space,Str "[",Emph [Str "nope"],Str "]\8230"]
155+,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"]
156+,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."]
155157,Header 2 ("empty-reference-links",[],[]) [Str "Empty",Space,Str "reference",Space,Str "links"]
156158,Para [Str "bar"]
157159,Para [Link [Str "foo2"] ("","")]]
tests/markdown-reader-more.txt+7
@@ -262,6 +262,13 @@ Empty cells
262262
263263[*not a link*] [*nope*]...
264264
265+## Reference link followed by a citation
266+
267+MapReduce is a paradigm popularized by [Google] [@mapreduce] as its
268+most vocal proponent.
269+
270+[Google]: http://google.com
271+
265272## Empty reference links
266273
267274[foo2]: