diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2014-12-15 10:50:10 -0800 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2014-12-15 10:54:12 -0800 | 
| commit | a5cac0a0c401b0d5c901ac734c877f6a32bddb40 (patch) | |
| tree | 78b2b46d898898cd308c2fb931ad6560b662584e | |
| parent | 9bf76fa5a256a20d03d251ec15f1785af9a7bb41 (diff) | |
| download | pandoc-a5cac0a0c401b0d5c901ac734c877f6a32bddb40.tar.gz | |
Don't treat a citation as a reference link label.
Closes #1763.
| -rw-r--r-- | README | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 7 | ||||
| -rw-r--r-- | tests/markdown-reader-more.native | 2 | ||||
| -rw-r--r-- | tests/markdown-reader-more.txt | 7 | 
4 files changed, 16 insertions, 4 deletions
| @@ -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  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 -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: diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 2ca3b0eb6..187b479c3 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1675,9 +1675,10 @@ referenceLink :: (String -> String -> Inlines -> Inlines)                -> (F Inlines, String) -> MarkdownParser (F Inlines)  referenceLink constructor (lab, raw) = do    sp <- (True <$ lookAhead (char ' ')) <|> return False -  (ref,raw') <- try -           (skipSpaces >> optional (newline >> skipSpaces) >> reference) -           <|> return (mempty, "") +  (ref,raw') <- option (mempty, "") $ +      lookAhead (try (spnl >> normalCite >> return (mempty, ""))) +      <|> +      try (spnl >> reference)    let labIsRef = raw' == "" || raw' == "[]"    let key = toKey $ if labIsRef then raw else raw'    parsedRaw <- parseFromString (mconcat <$> many inline) raw' diff --git a/tests/markdown-reader-more.native b/tests/markdown-reader-more.native index 00313a0ac..3f4bb5740 100644 --- a/tests/markdown-reader-more.native +++ b/tests/markdown-reader-more.native @@ -152,6 +152,8 @@  ,Para [Link [Str "linky"] ("hi_(there_(nested))","")]  ,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"] +,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"]  ,Para [Str "bar"]  ,Para [Link [Str "foo2"] ("","")]] diff --git a/tests/markdown-reader-more.txt b/tests/markdown-reader-more.txt index ea4fc9cad..d7439f6cb 100644 --- a/tests/markdown-reader-more.txt +++ b/tests/markdown-reader-more.txt @@ -262,6 +262,13 @@ Empty cells  [*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  [foo2]: | 
