git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: don't increment stateNoteNumber for example refs.

Background: syntactically, references to example list items can't be distinguished from citations; we only know which they are after we've parsed the whole document (and this is resolved in the `runF` stage). This means that pandoc's calculation of `citationNoteNum` can sometimes be wrong when there are example list references. This commit partially addresses #6836, but only for the case where the example list references refer to list items defined previously in the document.

commitb8d17f7ae8ed37784adcfaa4f89d0d28f52fffff authorJohn MacFarlane <jgm@berkeley.edu> dateSat 14 Nov 2020, 15:00 (6 years ago) parent68b298e
3 files changed+30−1
src/Text/Pandoc/Readers/Markdown.hs+12 test/command/6836.md+17 test/markdown-reader-more.native+1−1
src/Text/Pandoc/Readers/Markdown.hs+12
@@ -1535,6 +1535,11 @@ ltSign = do
15351535 char '<'
15361536 return $ return $ B.str "<"
15371537
1538+-- Note that if the citations extension is enabled, example refs will be
1539+-- parsed as citations, and handled by a clause in the parser for citations,
1540+-- since we won't know whether we have an example ref until the
1541+-- whole document has been parsed. But we need this parser
1542+-- here in case citations is disabled.
15381543exampleRef :: PandocMonad m => MarkdownParser m (F Inlines)
15391544exampleRef = try $ do
15401545 guardEnabled Ext_example_lists
@@ -2066,6 +2071,13 @@ cite = do
20662071textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
20672072textualCite = try $ do
20682073 (suppressAuthor, key) <- citeKey
2074+ -- If this is a reference to an earlier example list item,
2075+ -- then don't parse it as a citation. If the example list
2076+ -- item comes later, we'll parse it here and figure out in
2077+ -- the runF stage if it's a citation. But it helps with
2078+ -- issue #6836 to filter out known example list references
2079+ -- at this stage, so we don't increment stateNoteNumber.
2080+ getState >>= guard . isNothing . M.lookup key . stateExamples
20692081 noteNum <- stateNoteNumber <$> getState
20702082 let first = Citation{ citationId = key
20712083 , citationPrefix = []
test/command/6836.mdnew file+17
@@ -0,0 +1,17 @@
1+```
2+pandoc -t native
3+[@buchanan]
4+
5+(@foo)
6+
7+See @foo.
8+
9+[@buchanan]
10+^D
11+[Para [Cite [Citation {citationId = "buchanan", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 1, citationHash = 0}] [Str "[@buchanan]"]]
12+,OrderedList (1,Example,TwoParens)
13+ [[]]
14+,Para [Str "See",Space,Str "1."]
15+,Para [Cite [Citation {citationId = "buchanan", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 2, citationHash = 0}] [Str "[@buchanan]"]]]
16+```
17+
test/markdown-reader-more.native+1−1
@@ -328,7 +328,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
328328,Header 2 ("reference-link-fallbacks",[],[]) [Str "Reference",Space,Str "link",Space,Str "fallbacks"]
329329,Para [Str "[",Emph [Str "not",Space,Str "a",Space,Str "link"],Str "]",Space,Str "[",Emph [Str "nope"],Str "]\8230"]
330330,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"]
331−,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 = 3, citationHash = 0}] [Str "[@mapreduce]"],Space,Str "as",Space,Str "its",SoftBreak,Str "most",Space,Str "vocal",Space,Str "proponent."]
331+,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 = 2, citationHash = 0}] [Str "[@mapreduce]"],Space,Str "as",Space,Str "its",SoftBreak,Str "most",Space,Str "vocal",Space,Str "proponent."]
332332,Header 2 ("empty-reference-links",[],[]) [Str "Empty",Space,Str "reference",Space,Str "links"]
333333,Para [Str "bar"]
334334,Para [Link ("",[],[]) [Str "foo2"] ("","")]