diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2024-02-03 22:19:29 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2024-02-03 22:19:29 -0800 |
| commit | 03bb426a4a65918bfd6fbd63d5bb32a657df5568 (patch) | |
| tree | ebd0629088e86f25c35467c46ba19ac1ce37ec36 /src/Text/Pandoc/Writers/HTML.hs | |
| parent | 6fc8a80c2cdeaf71b7fe6d20c35b46ef562ca67c (diff) | |
Shared: `makeSections` behavior changes.
+ When the optional base level parameter is provided, we no
longer ensure that the sequence of heading levels is gapless
[behavior change]. Instead, we set the lowest heading level to
the specified base level, and adjust the others accordingly. If
an author wants to skip a level, e.g. from level 1 to level 3,
they can do that. In general, the heading levels specified
in the source document are preserved; `makeSections` only
puts them into a hierarchical structure. Closes #9398.
+ Section numbers are now assigned so that the top level
gets `1`, no matter what heading level is used. So, even
if the top heading level is 2, numbers will be `1`, `2`, etc.
rather than `0.1`, `0.2`, as in the past. Closes #5071.
+ We revert to the old behavior when the `--number-offset` option
is used. So, for example, if a document begins with a level-3
heading, and `--number-offset=1,2` is used, the top-level section
numbers will be `1.2.1`, `1.2.2`, etc. This is mainly for
backwards-compatibility.
Diffstat (limited to 'src/Text/Pandoc/Writers/HTML.hs')
| -rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 18e10f102..c7a4703ae 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -721,17 +721,22 @@ adjustNumbers opts doc = then doc else walk go doc where - go (Div (ident,"section":classes,kvs) lst) = - Div (ident,"section":classes,map fixnum kvs) lst + go (Div (ident,"section":classes,kvs) lst@(Header level _ _ : _)) = + Div (ident,"section":classes,map (fixnum level) kvs) lst go (Header level (ident,classes,kvs) lst) = - Header level (ident,classes,map fixnum kvs) lst + Header level (ident,classes,map (fixnum level) kvs) lst go x = x - fixnum ("number",num) = ("number", + fixnum level ("number",num) = ("number", showSecNum $ zipWith (+) (writerNumberOffset opts ++ repeat 0) - (map (fromMaybe 0 . safeRead) $ + (padTo level $ + map (fromMaybe 0 . safeRead) $ T.split (=='.') num)) - fixnum x = x + fixnum _ x = x + padTo n xs = + case n - length xs of + x | x > 0 -> replicate x 0 ++ xs + | otherwise -> xs showSecNum = T.intercalate "." . map tshow blockToHtmlInner :: PandocMonad m => WriterOptions -> Block -> StateT WriterState m Html |
