aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-11-14 15:00:17 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-11-14 15:00:17 -0800
commitb8d17f7ae8ed37784adcfaa4f89d0d28f52fffff (patch)
treeb1319041b8f6f17efe4432d1306129e38fa9e9ab /src/Text/Pandoc
parent68b298ed9aee405033da9a2b44ae86f2241a123d (diff)
downloadpandoc-b8d17f7ae8ed37784adcfaa4f89d0d28f52fffff.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 64a2db288..e62a8a978 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1535,6 +1535,11 @@ ltSign = do
char '<'
return $ return $ B.str "<"
+-- Note that if the citations extension is enabled, example refs will be
+-- parsed as citations, and handled by a clause in the parser for citations,
+-- since we won't know whether we have an example ref until the
+-- whole document has been parsed. But we need this parser
+-- here in case citations is disabled.
exampleRef :: PandocMonad m => MarkdownParser m (F Inlines)
exampleRef = try $ do
guardEnabled Ext_example_lists
@@ -2066,6 +2071,13 @@ cite = do
textualCite :: PandocMonad m => MarkdownParser m (F Inlines)
textualCite = try $ do
(suppressAuthor, key) <- citeKey
+ -- If this is a reference to an earlier example list item,
+ -- then don't parse it as a citation. If the example list
+ -- item comes later, we'll parse it here and figure out in
+ -- the runF stage if it's a citation. But it helps with
+ -- issue #6836 to filter out known example list references
+ -- at this stage, so we don't increment stateNoteNumber.
+ getState >>= guard . isNothing . M.lookup key . stateExamples
noteNum <- stateNoteNumber <$> getState
let first = Citation{ citationId = key
, citationPrefix = []