diff options
| author | John MacFarlane <[email protected]> | 2025-01-31 11:44:48 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-01-31 11:44:48 -0800 |
| commit | 6fbb50fc88c841e181a11f5aabf958cd39b04290 (patch) | |
| tree | 598489ba8389c99de46697126d4d1a4d21cdd123 /src | |
| parent | a14fe6f446fd47be9542d5b5ba4c14cb1524fed3 (diff) | |
Docx writer: repeat reference doc's sectPr for each new section.
Previously we were only carrying over the reference doc's sectPr
at the end of the document, so it wouldn't affect the intermediate
sections that are now added if `--top-level-division` is `chapter`
or `part`. This could lead to bad results (e.g. page numbering
starting only on the last chapter).
Closes #10577.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 17 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx/OpenXML.hs | 11 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx/Types.hs | 2 |
3 files changed, 17 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 635155b0d..7fb539289 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -239,20 +239,17 @@ writeDocx opts doc = do (\q -> qName q == "id" && qPrefix q == Just "r") idMap (elChildren sectpr') - in Just . ppElement $ - add_attrs (elAttribs sectpr') $ mknode "w:sectPr" [] cs - Nothing -> Nothing - + in add_attrs (elAttribs sectpr') $ mknode "w:sectPr" [] cs + Nothing -> mknode "w:sectPr" [] + [ mknode "w:footnotePr" [] + [ mknode "w:numRestart" [("w:val","eachSect")] () ] + ] ((contents, footnotes, comments), st) <- runStateT (runReaderT - (writeOpenXML opts{ writerWrapText = WrapNone - , writerVariables = - (maybe id (setField "sectpr") sectpr) - (writerVariables opts) - } + (writeOpenXML opts{ writerWrapText = WrapNone } doc') - env) + env{ envSectPr = Just sectpr }) initialSt let epochtime = floor $ utcTimeToPOSIXSeconds utctime let imgs = M.elems $ stImages st diff --git a/src/Text/Pandoc/Writers/Docx/OpenXML.hs b/src/Text/Pandoc/Writers/Docx/OpenXML.hs index 54f3ed84a..a6f6ad4d1 100644 --- a/src/Text/Pandoc/Writers/Docx/OpenXML.hs +++ b/src/Text/Pandoc/Writers/Docx/OpenXML.hs @@ -288,6 +288,8 @@ writeOpenXML opts (Pandoc meta blocks) = do meta cStyleMap <- gets (smParaStyle . stStyleMaps) let styleIdOf name = fromStyleId $ getStyleIdFromName name cStyleMap + renderedSectPr <- maybe mempty ppElement <$> asks envSectPr + let context = resetField "body" body . resetField "toc" (vcat (map (literal . showElement) toc)) @@ -307,6 +309,7 @@ writeOpenXML opts (Pandoc meta blocks) = do . resetField "date-style-id" (styleIdOf "Date") . resetField "abstract-title-style-id" (styleIdOf "AbstractTitle") . resetField "abstract-style-id" (styleIdOf "Abstract") + . resetField "sectpr" renderedSectPr $ metadata tpl <- maybe (lift $ compileDefaultTemplate "openxml") pure $ writerTemplate opts let rendered = render Nothing $ renderTemplate tpl context @@ -392,10 +395,12 @@ blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do Nothing -> return [] else return [] contents <- (number ++) <$> inlinesToOpenXML opts lst + sectpr <- asks envSectPr let addSectionBreak - | isSection = (Elem (mknode "w:p" [] - (mknode "w:pPr" [] - [mknode "w:sectPr" [] ()])) :) + | isSection + , Just sectPrElem <- sectpr + = (Elem (mknode "w:p" [] + (mknode "w:pPr" [] [sectPrElem])) :) | otherwise = id addSectionBreak <$> if T.null ident diff --git a/src/Text/Pandoc/Writers/Docx/Types.hs b/src/Text/Pandoc/Writers/Docx/Types.hs index afa98be64..bf3e0248c 100644 --- a/src/Text/Pandoc/Writers/Docx/Types.hs +++ b/src/Text/Pandoc/Writers/Docx/Types.hs @@ -89,6 +89,7 @@ data WriterEnv = WriterEnv , envChangesDate :: Text , envPrintWidth :: Integer , envLang :: Maybe Text + , envSectPr :: Maybe Element } defaultWriterEnv :: WriterEnv @@ -104,6 +105,7 @@ defaultWriterEnv = WriterEnv , envChangesDate = "1969-12-31T19:00:00Z" , envPrintWidth = 1 , envLang = Nothing + , envSectPr = Nothing } |
