aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-01-31 11:44:48 -0800
committerJohn MacFarlane <[email protected]>2025-01-31 11:44:48 -0800
commit6fbb50fc88c841e181a11f5aabf958cd39b04290 (patch)
tree598489ba8389c99de46697126d4d1a4d21cdd123
parenta14fe6f446fd47be9542d5b5ba4c14cb1524fed3 (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.
-rw-r--r--data/templates/default.openxml9
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs17
-rw-r--r--src/Text/Pandoc/Writers/Docx/OpenXML.hs11
-rw-r--r--src/Text/Pandoc/Writers/Docx/Types.hs2
-rw-r--r--test/docx/golden/block_quotes.docxbin10683 -> 10691 bytes
-rw-r--r--test/docx/golden/codeblock.docxbin10500 -> 10508 bytes
-rw-r--r--test/docx/golden/comments.docxbin10830 -> 10839 bytes
-rw-r--r--test/docx/golden/custom_style_no_reference.docxbin10602 -> 10610 bytes
-rw-r--r--test/docx/golden/custom_style_preserve.docxbin11227 -> 11235 bytes
-rw-r--r--test/docx/golden/custom_style_reference.docxbin12470 -> 12543 bytes
-rw-r--r--test/docx/golden/definition_list.docxbin10498 -> 10507 bytes
-rw-r--r--test/docx/golden/document-properties-short-desc.docxbin10501 -> 10512 bytes
-rw-r--r--test/docx/golden/document-properties.docxbin10989 -> 10998 bytes
-rw-r--r--test/docx/golden/headers.docxbin10643 -> 10652 bytes
-rw-r--r--test/docx/golden/image.docxbin27381 -> 27388 bytes
-rw-r--r--test/docx/golden/inline_code.docxbin10441 -> 10449 bytes
-rw-r--r--test/docx/golden/inline_formatting.docxbin10618 -> 10625 bytes
-rw-r--r--test/docx/golden/inline_images.docxbin27375 -> 27384 bytes
-rw-r--r--test/docx/golden/link_in_notes.docxbin10657 -> 10666 bytes
-rw-r--r--test/docx/golden/links.docxbin10832 -> 10840 bytes
-rw-r--r--test/docx/golden/lists.docxbin11027 -> 11034 bytes
-rw-r--r--test/docx/golden/lists_9994.docxbin10779 -> 10786 bytes
-rw-r--r--test/docx/golden/lists_continuing.docxbin10694 -> 10700 bytes
-rw-r--r--test/docx/golden/lists_div_bullets.docxbin10677 -> 10684 bytes
-rw-r--r--test/docx/golden/lists_multiple_initial.docxbin10909 -> 10916 bytes
-rw-r--r--test/docx/golden/lists_restarting.docxbin10691 -> 10697 bytes
-rw-r--r--test/docx/golden/nested_anchors_in_header.docxbin10835 -> 10841 bytes
-rw-r--r--test/docx/golden/notes.docxbin10606 -> 10611 bytes
-rw-r--r--test/docx/golden/raw-blocks.docxbin10534 -> 10542 bytes
-rw-r--r--test/docx/golden/raw-bookmarks.docxbin10673 -> 10681 bytes
-rw-r--r--test/docx/golden/table_one_row.docxbin10512 -> 10520 bytes
-rw-r--r--test/docx/golden/table_with_list_cell.docxbin10964 -> 10970 bytes
-rw-r--r--test/docx/golden/tables-default-widths.docxbin10875 -> 10883 bytes
-rw-r--r--test/docx/golden/tables.docxbin10889 -> 10896 bytes
-rw-r--r--test/docx/golden/tables_separated_with_rawblock.docxbin10509 -> 10517 bytes
-rw-r--r--test/docx/golden/task_list.docxbin10774 -> 10781 bytes
-rw-r--r--test/docx/golden/track_changes_deletion.docxbin10481 -> 10490 bytes
-rw-r--r--test/docx/golden/track_changes_insertion.docxbin10464 -> 10474 bytes
-rw-r--r--test/docx/golden/track_changes_move.docxbin10496 -> 10504 bytes
-rw-r--r--test/docx/golden/track_changes_scrubbed_metadata.docxbin10609 -> 10615 bytes
-rw-r--r--test/docx/golden/unicode.docxbin10458 -> 10466 bytes
-rw-r--r--test/docx/golden/verbatim_subsuper.docxbin10470 -> 10477 bytes
42 files changed, 17 insertions, 22 deletions
diff --git a/data/templates/default.openxml b/data/templates/default.openxml
index b86efffa2..1344857fe 100644
--- a/data/templates/default.openxml
+++ b/data/templates/default.openxml
@@ -60,15 +60,6 @@ $endif$
$for(include-after)$
$include-after$
$endfor$
-$-- sectpr will be set to the last sectpr in a reference.docx, if present
-$if(sectpr)$
$sectpr$
-$else$
- <w:sectPr>
- <w:footnotePr>
- <w:numRestart w:val="eachSect" />
- </w:footnotePr>
- </w:sectPr>
-$endif$
</w:body>
</w:document>
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
}
diff --git a/test/docx/golden/block_quotes.docx b/test/docx/golden/block_quotes.docx
index 645219158..214a57a5b 100644
--- a/test/docx/golden/block_quotes.docx
+++ b/test/docx/golden/block_quotes.docx
Binary files differ
diff --git a/test/docx/golden/codeblock.docx b/test/docx/golden/codeblock.docx
index 870a66488..9aa1dd858 100644
--- a/test/docx/golden/codeblock.docx
+++ b/test/docx/golden/codeblock.docx
Binary files differ
diff --git a/test/docx/golden/comments.docx b/test/docx/golden/comments.docx
index 4ea20162d..41eb630ea 100644
--- a/test/docx/golden/comments.docx
+++ b/test/docx/golden/comments.docx
Binary files differ
diff --git a/test/docx/golden/custom_style_no_reference.docx b/test/docx/golden/custom_style_no_reference.docx
index 336f52963..ff7b8c477 100644
--- a/test/docx/golden/custom_style_no_reference.docx
+++ b/test/docx/golden/custom_style_no_reference.docx
Binary files differ
diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx
index e1d8c7656..8afe51ecd 100644
--- a/test/docx/golden/custom_style_preserve.docx
+++ b/test/docx/golden/custom_style_preserve.docx
Binary files differ
diff --git a/test/docx/golden/custom_style_reference.docx b/test/docx/golden/custom_style_reference.docx
index 149b3db55..e4dd93f47 100644
--- a/test/docx/golden/custom_style_reference.docx
+++ b/test/docx/golden/custom_style_reference.docx
Binary files differ
diff --git a/test/docx/golden/definition_list.docx b/test/docx/golden/definition_list.docx
index cfd4ed19b..ed52ddde7 100644
--- a/test/docx/golden/definition_list.docx
+++ b/test/docx/golden/definition_list.docx
Binary files differ
diff --git a/test/docx/golden/document-properties-short-desc.docx b/test/docx/golden/document-properties-short-desc.docx
index 454e33bdc..8af10827a 100644
--- a/test/docx/golden/document-properties-short-desc.docx
+++ b/test/docx/golden/document-properties-short-desc.docx
Binary files differ
diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx
index 8a55e5159..6d151023f 100644
--- a/test/docx/golden/document-properties.docx
+++ b/test/docx/golden/document-properties.docx
Binary files differ
diff --git a/test/docx/golden/headers.docx b/test/docx/golden/headers.docx
index aa143b935..c6bec6ca4 100644
--- a/test/docx/golden/headers.docx
+++ b/test/docx/golden/headers.docx
Binary files differ
diff --git a/test/docx/golden/image.docx b/test/docx/golden/image.docx
index d500aea2e..ab841908c 100644
--- a/test/docx/golden/image.docx
+++ b/test/docx/golden/image.docx
Binary files differ
diff --git a/test/docx/golden/inline_code.docx b/test/docx/golden/inline_code.docx
index 2b4089cff..f8dd88987 100644
--- a/test/docx/golden/inline_code.docx
+++ b/test/docx/golden/inline_code.docx
Binary files differ
diff --git a/test/docx/golden/inline_formatting.docx b/test/docx/golden/inline_formatting.docx
index 20e89d675..9e83fa0e3 100644
--- a/test/docx/golden/inline_formatting.docx
+++ b/test/docx/golden/inline_formatting.docx
Binary files differ
diff --git a/test/docx/golden/inline_images.docx b/test/docx/golden/inline_images.docx
index 2678b3528..b76cf6417 100644
--- a/test/docx/golden/inline_images.docx
+++ b/test/docx/golden/inline_images.docx
Binary files differ
diff --git a/test/docx/golden/link_in_notes.docx b/test/docx/golden/link_in_notes.docx
index 29605d686..fc8326472 100644
--- a/test/docx/golden/link_in_notes.docx
+++ b/test/docx/golden/link_in_notes.docx
Binary files differ
diff --git a/test/docx/golden/links.docx b/test/docx/golden/links.docx
index 37f6547cc..5b1fce508 100644
--- a/test/docx/golden/links.docx
+++ b/test/docx/golden/links.docx
Binary files differ
diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx
index 3a7e958d9..99ccd88a7 100644
--- a/test/docx/golden/lists.docx
+++ b/test/docx/golden/lists.docx
Binary files differ
diff --git a/test/docx/golden/lists_9994.docx b/test/docx/golden/lists_9994.docx
index 33c3f9f20..a43d1869b 100644
--- a/test/docx/golden/lists_9994.docx
+++ b/test/docx/golden/lists_9994.docx
Binary files differ
diff --git a/test/docx/golden/lists_continuing.docx b/test/docx/golden/lists_continuing.docx
index a36bfa447..f9409df00 100644
--- a/test/docx/golden/lists_continuing.docx
+++ b/test/docx/golden/lists_continuing.docx
Binary files differ
diff --git a/test/docx/golden/lists_div_bullets.docx b/test/docx/golden/lists_div_bullets.docx
index 6668376f3..ee504f3c1 100644
--- a/test/docx/golden/lists_div_bullets.docx
+++ b/test/docx/golden/lists_div_bullets.docx
Binary files differ
diff --git a/test/docx/golden/lists_multiple_initial.docx b/test/docx/golden/lists_multiple_initial.docx
index 4f5bca663..593fe03b5 100644
--- a/test/docx/golden/lists_multiple_initial.docx
+++ b/test/docx/golden/lists_multiple_initial.docx
Binary files differ
diff --git a/test/docx/golden/lists_restarting.docx b/test/docx/golden/lists_restarting.docx
index 9a3545bd8..5cbe7b24e 100644
--- a/test/docx/golden/lists_restarting.docx
+++ b/test/docx/golden/lists_restarting.docx
Binary files differ
diff --git a/test/docx/golden/nested_anchors_in_header.docx b/test/docx/golden/nested_anchors_in_header.docx
index be8b3702a..a97cd445b 100644
--- a/test/docx/golden/nested_anchors_in_header.docx
+++ b/test/docx/golden/nested_anchors_in_header.docx
Binary files differ
diff --git a/test/docx/golden/notes.docx b/test/docx/golden/notes.docx
index 2089ff544..2562cceb3 100644
--- a/test/docx/golden/notes.docx
+++ b/test/docx/golden/notes.docx
Binary files differ
diff --git a/test/docx/golden/raw-blocks.docx b/test/docx/golden/raw-blocks.docx
index 50f625017..145801c0e 100644
--- a/test/docx/golden/raw-blocks.docx
+++ b/test/docx/golden/raw-blocks.docx
Binary files differ
diff --git a/test/docx/golden/raw-bookmarks.docx b/test/docx/golden/raw-bookmarks.docx
index 8777b74de..6e774aa15 100644
--- a/test/docx/golden/raw-bookmarks.docx
+++ b/test/docx/golden/raw-bookmarks.docx
Binary files differ
diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx
index 560d001a9..abbe767a5 100644
--- a/test/docx/golden/table_one_row.docx
+++ b/test/docx/golden/table_one_row.docx
Binary files differ
diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx
index 954be9402..8477a7cf1 100644
--- a/test/docx/golden/table_with_list_cell.docx
+++ b/test/docx/golden/table_with_list_cell.docx
Binary files differ
diff --git a/test/docx/golden/tables-default-widths.docx b/test/docx/golden/tables-default-widths.docx
index 97086cc7f..790d8cd63 100644
--- a/test/docx/golden/tables-default-widths.docx
+++ b/test/docx/golden/tables-default-widths.docx
Binary files differ
diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx
index cebbe1af9..1b80a7904 100644
--- a/test/docx/golden/tables.docx
+++ b/test/docx/golden/tables.docx
Binary files differ
diff --git a/test/docx/golden/tables_separated_with_rawblock.docx b/test/docx/golden/tables_separated_with_rawblock.docx
index b7cfc7c24..fd8c68c06 100644
--- a/test/docx/golden/tables_separated_with_rawblock.docx
+++ b/test/docx/golden/tables_separated_with_rawblock.docx
Binary files differ
diff --git a/test/docx/golden/task_list.docx b/test/docx/golden/task_list.docx
index 7dbace1e4..2ca6c7d77 100644
--- a/test/docx/golden/task_list.docx
+++ b/test/docx/golden/task_list.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx
index 027df017a..f3fd20137 100644
--- a/test/docx/golden/track_changes_deletion.docx
+++ b/test/docx/golden/track_changes_deletion.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_insertion.docx b/test/docx/golden/track_changes_insertion.docx
index 346e0a818..a791641a0 100644
--- a/test/docx/golden/track_changes_insertion.docx
+++ b/test/docx/golden/track_changes_insertion.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_move.docx b/test/docx/golden/track_changes_move.docx
index 5b33a4ec1..fb25a5bbb 100644
--- a/test/docx/golden/track_changes_move.docx
+++ b/test/docx/golden/track_changes_move.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_scrubbed_metadata.docx b/test/docx/golden/track_changes_scrubbed_metadata.docx
index 9e98c3a90..6305c0d59 100644
--- a/test/docx/golden/track_changes_scrubbed_metadata.docx
+++ b/test/docx/golden/track_changes_scrubbed_metadata.docx
Binary files differ
diff --git a/test/docx/golden/unicode.docx b/test/docx/golden/unicode.docx
index 8e46a5be2..ccd92baa4 100644
--- a/test/docx/golden/unicode.docx
+++ b/test/docx/golden/unicode.docx
Binary files differ
diff --git a/test/docx/golden/verbatim_subsuper.docx b/test/docx/golden/verbatim_subsuper.docx
index 88a2ad365..55323f885 100644
--- a/test/docx/golden/verbatim_subsuper.docx
+++ b/test/docx/golden/verbatim_subsuper.docx
Binary files differ