diff --git a/MANUAL.txt b/MANUAL.txt index 163cb4259..cec4c667d 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -4726,6 +4726,17 @@ This only works reliably, though, if the repeated item is in a list by itself, because each numbered example list will be numbered continuously from its starting number. +In a longer (book-length) work, one might need to reset the example +list counter at the beginning of each chapter. One can do that using the +following syntax: + + (1@foo) This item will be numbered 1, and subsequent example + list items will be numbered 2, 3, etc. + +Any number may be used instead of `1`. Note that if there are several +example list items in a row, the number only has an effect if placed +on the first of them. + ### Ending a list ### What if you want to put an indented code block after a list? diff --git a/src/Text/Pandoc/Parsing/Lists.hs b/src/Text/Pandoc/Parsing/Lists.hs index 14ca22a31..fc39a9959 100644 --- a/src/Text/Pandoc/Parsing/Lists.hs +++ b/src/Text/Pandoc/Parsing/Lists.hs @@ -112,12 +112,16 @@ decimal = do exampleNum :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s ParserState m (ListNumberStyle, Int) exampleNum = do + mbNum <- safeRead . T.pack <$> many digit char '@' lab <- T.pack . concat <$> many (many1 alphaNum <|> try (do c <- char '_' <|> char '-' cs <- many1 alphaNum return (c:cs))) + case mbNum of + Nothing -> pure () + Just n -> updateState $ \s -> s{ stateNextExample = n } st <- getState case M.lookup lab (stateExamples st) of Nothing -> do -- new label diff --git a/test/command/10940.md b/test/command/10940.md new file mode 100644 index 000000000..e739c9526 --- /dev/null +++ b/test/command/10940.md @@ -0,0 +1,27 @@ +``` +% pandoc -t plain +# Chapter one + +(@foo) an example list. +(@) second item. + +# Chapter two + +(1@bar) reset the counter to one. +(@) another. + +Foo is (@foo) and bar is (@bar). +^D +Chapter one + +(1) an example list. +(2) second item. + +Chapter two + +(1) reset the counter to one. +(2) another. + +Foo is (1) and bar is (1). + +```