diff options
| author | John MacFarlane <[email protected]> | 2024-12-22 11:38:32 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-12-22 11:38:32 -0800 |
| commit | dc6a7d06b1fa9ec8f2393a8874194832c677c4c5 (patch) | |
| tree | c1c5044e355a652be7b689f6b8f62277703816f7 /src | |
| parent | d9281d1eaf5e52f8bad383eb36af02168555e91a (diff) | |
Docx writer: better handling of chapters.
When `--top-level-division=chapter` is used, a paragraph with
section properties is inserted before each level-1 heading.
By default, this causes the new heading to start on a new page
(though this default can be adjusted in Word).
This change should also make it possible to number footnotes
by chapter (#2773), though that change isn't yet made.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx/OpenXML.hs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/Docx/OpenXML.hs b/src/Text/Pandoc/Writers/Docx/OpenXML.hs index 6713d9c07..cfe6b106e 100644 --- a/src/Text/Pandoc/Writers/Docx/OpenXML.hs +++ b/src/Text/Pandoc/Writers/Docx/OpenXML.hs @@ -375,6 +375,7 @@ blockToOpenXML' opts (Div (ident,_classes,kvs) bs) = do wrapBookmark ident $ header <> contents blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do setFirstPara + let isChapter = lev == 1 && writerTopLevelDivision opts == TopLevelChapter paraProps <- withParaPropM (pStyleM (fromString $ "Heading "++show lev)) $ getParaProps False number <- @@ -388,14 +389,20 @@ blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do Nothing -> return [] else return [] contents <- (number ++) <$> inlinesToOpenXML opts lst - if T.null ident - then return [Elem $ mknode "w:p" [] (map Elem paraProps ++ contents)] - else do - let bookmarkName = ident - modify $ \s -> s{ stSectionIds = Set.insert bookmarkName - $ stSectionIds s } - bookmarkedContents <- wrapBookmark bookmarkName contents - return [Elem $ mknode "w:p" [] (map Elem paraProps ++ bookmarkedContents)] + let addSectionBreak + | isChapter = (Elem (mknode "w:p" [] + (mknode "w:pPr" [] + [mknode "w:sectPr" [] ()])) :) + | otherwise = id + addSectionBreak <$> + if T.null ident + then return [Elem $ mknode "w:p" [] (map Elem paraProps ++ contents)] + else do + let bookmarkName = ident + modify $ \s -> s{ stSectionIds = Set.insert bookmarkName + $ stSectionIds s } + bookmarkedContents <- wrapBookmark bookmarkName contents + return [Elem $ mknode "w:p" [] (map Elem paraProps ++ bookmarkedContents)] blockToOpenXML' opts (Plain lst) = do isInTable <- gets stInTable isInList <- gets stInList |
