From f6edf03303d909332896f93ddf81d5f693c670aa Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 7 Jul 2026 20:58:33 +0200 Subject: [PATCH] Shared: Improve `makeSections`. Previously it would sometimes create doubled section divs. By leaving the inner heading's id on the heading itself, and then consolidating the inner and outer section divs, we can avoid this undesirable result. Closes #11745. --- src/Text/Pandoc/Shared.hs | 21 +++++++++++++++------ test/command/11745.md | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 test/command/11745.md diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 41eefd198..12e74b53b 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -569,16 +569,25 @@ makeSectionsWithOffsets numoffsets numbering mbBaseLevel bs = | all (\case Header level' _ _ -> level' > level _ -> True) ys - , "column" `notElem` dclasses - , "columns" `notElem` dclasses - , "fragment" `notElem` dclasses = do + , "section" `elem` dclasses + || ("column" `notElem` dclasses && + "columns" `notElem` dclasses && + "fragment" `notElem` dclasses && + "cell" `notElem` dclasses) = do inner <- go (Header level hattr title':ys) rest <- go xs return $ case inner of - [Div divattr'@(dident',_,_) zs] - | T.null dident || T.null dident' || dident == dident' - -> Div (combineAttr divattr' divattr) zs : rest + [Div divattr'@(dident',_,_) zs@(Header level' hattr' title'' : zs')] + | dident == dident' + -> Div (combineAttr divattr' divattr) zs : rest + | (_,dclasses',dkvs) <- combineAttr divattr' divattr + , ("",hclasses,hkvs) <- hattr' + -> if T.null dident + then Div (dident',dclasses',dkvs) zs : rest + else Div (dident,dclasses',dkvs) + (Header level' (dident',hclasses,hkvs) title'' + : zs') : rest _ -> Div divattr inner : rest go (Div attr xs : rest) = do xs' <- go xs diff --git a/test/command/11745.md b/test/command/11745.md new file mode 100644 index 000000000..07e4fa42c --- /dev/null +++ b/test/command/11745.md @@ -0,0 +1,26 @@ +``` +% pandoc --section-divs +# Book Title + +::: {#ch1 .section} +## Chapter 1 +Hello world. +::: + +::: {#ch2 .section} +## Chapter 2 +Goodbye world. +::: +^D +
+

Book Title

+
+

Chapter 1

+

Hello world.

+
+
+

Chapter 2

+

Goodbye world.

+
+
+```