Markdown reader: Add a syntax for resetting example list counter.

This is needed often at the beginning of a chapter.

Closes #10940.
This commit is contained in:
John MacFarlane
2026-08-24 11:58:10 -07:00
parent 14b0ec95c8
commit 5727e10827
3 changed files with 42 additions and 0 deletions
+11
View File
@@ -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?
+4
View File
@@ -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
+27
View File
@@ -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).
```