diff options
| author | John MacFarlane <[email protected]> | 2023-12-17 17:03:14 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-12-17 17:03:14 -0800 |
| commit | c9bf4da74ffa21b4cf4b5fdfdcf02807db5dc5bd (patch) | |
| tree | 7e8e6b583f8b5034424e962d4988b8209ff6685f | |
| parent | 3abbf97d0bfb17c6ffe26ff8079b93f5cf2faa5d (diff) | |
Docx writer: ensure that elements in settings are ordered correctly.
The elements must occur in a specific order. This was being
messed up when integrating a custom reference.docx. Closes #9264.
37 files changed, 99 insertions, 24 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 1a2cc79a4..e89ec4801 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -28,7 +28,7 @@ import Codec.Archive.Zip toEntry, Entry(eRelativePath) ) import Control.Applicative ((<|>)) -import Control.Monad (MonadPlus(mplus), unless, when) +import Control.Monad (MonadPlus(mplus), unless, when, foldM) import Control.Monad.Except (catchError, throwError) import Control.Monad.Reader ( asks, MonadReader(local), MonadTrans(lift), ReaderT(runReaderT) ) @@ -508,30 +508,105 @@ writeDocx opts doc = do -- adds references to footnotes or endnotes we don't have... -- we do, however, copy some settings over from reference let settingsPath = "word/settings.xml" - settingsList = [ "zoom" - , "mirrorMargins" + + settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime + -- note: these must go in the following order: + [ "writeProtection" + , "view" + , "zoom" + , "removePersonalInformation" + , "removeDateAndTime" + , "doNotDisplayPageBoundaries" + , "displayBackgroundShape" + , "printPostScriptOverText" + , "printFractionalCharacterWidth" + , "printFormsData" + , "embedTrueTypeFonts" , "embedSystemFonts" + , "saveSubsetFonts" + , "saveFormsData" + , "mirrorMargins" + , "alignBordersAndEdges" + , "bordersDoNotSurroundHeader" + , "bordersDoNotSurroundFooter" + , "gutterAtTop" + , "hideSpellingErrors" + , "hideGrammaticalErrors" + , "activeWritingStyle" + , "proofState" + , "formsDesign" + , "attachedTemplate" + , "linkStyles" + , "stylePaneFormatFilter" + , "stylePaneSortMethod" + , "documentType" + , "mailMerge" + , "revisionView" + , "trackRevisions" , "doNotTrackMoves" + , "doNotTrackFormatting" + , "documentProtection" + , "autoFormatOverride" + , "styleLockTheme" + , "styleLockQFSet" , "defaultTabStop" + , "autoHyphenation" + , "consecutiveHyphenLimit" + , "hyphenationZone" + , "doNotHyphenateCaps" + , "showEnvelope" + , "summaryLength" + , "clickAndTypeStyle" + , "defaultTableStyle" + , "evenAndOddHeaders" + , "bookFoldRevPrinting" + , "bookFoldPrinting" + , "bookFoldPrintingSheets" , "drawingGridHorizontalSpacing" , "drawingGridVerticalSpacing" , "displayHorizontalDrawingGridEvery" , "displayVerticalDrawingGridEvery" + , "doNotUseMarginsForDrawingGridOrigin" + , "drawingGridHorizontalOrigin" + , "drawingGridVerticalOrigin" + , "doNotShadeFormData" + , "noPunctuationKerning" , "characterSpacingControl" + , "printTwoOnOne" + , "strictFirstAndLastChars" + , "noLineBreaksAfter" + , "noLineBreaksBefore" , "savePreviewPicture" - , "mathPr" + , "doNotValidateAgainstSchema" + , "saveInvalidXml" + , "ignoreMixedContent" + , "alwaysShowPlaceholderText" + , "doNotDemarcateInvalidXml" + , "saveXmlDataOnly" + , "useXSLTWhenSaving" + , "saveThroughXslt" + , "showXMLTags" + , "alwaysMergeEmptyNamespace" + , "updateFields" + , "hdrShapeDefaults" + , "footnotePr" + , "endnotePr" + , "compat" + , "docVars" + , "rsids" + , "attachedSchema" , "themeFontLang" + , "clrSchemeMapping" + , "doNotIncludeSubdocsInStats" + , "doNotAutoCompressPictures" + , "forceUpgrade" + , "captions" + , "readModeInkLockDown" + , "smartTagType" + , "shapeDefaults" + , "doNotEmbedSmartTags" , "decimalSymbol" - , "listSeparator" - , "autoHyphenation" - , "consecutiveHyphenLimit" - , "hyphenationZone" - , "doNotHyphenateCap" - , "evenAndOddHeaders" - , "proofState" - , "compat" - ] - settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList + , "listSeparator" ] let entryFromArchive arch path = maybe (throwError $ PandocSomeError @@ -639,17 +714,17 @@ copyChildren :: (PandocMonad m) copyChildren refArchive distArchive path timestamp elNames = do ref <- parseXml refArchive distArchive path dist <- parseXml distArchive distArchive path - let elsToCopy = - map cleanElem $ filterChildrenName (\e -> qName e `elem` elNames) ref - let elsToKeep = - [e | Elem e <- elContent dist, not (any (hasSameNameAs e) elsToCopy)] - return $ toEntry path timestamp $ renderXml dist{ - elContent = map Elem elsToKeep ++ map Elem elsToCopy - } + els <- foldM (addEl ref dist) [] (reverse elNames) + return $ toEntry path timestamp + $ renderXml dist{ elContent = map cleanElem els } where - hasSameNameAs (Element {elName = n1}) (Element {elName = n2}) = - qName n1 == qName n2 - cleanElem el@Element{elName=name} = el{elName=name{qURI=Nothing}} + addEl ref dist els name = + case filterChildName (hasName name) ref `mplus` + filterChildName (hasName name) dist of + Just el -> pure (el : els) + Nothing -> pure els + hasName name = (== name) . qName + cleanElem el@Element{elName=name} = Elem el{elName=name{qURI=Nothing}} -- this is the lowest number used for a list numId baseListId :: Int diff --git a/test/docx/golden/block_quotes.docx b/test/docx/golden/block_quotes.docx Binary files differindex 2c00e9ef0..e1e296f9e 100644 --- a/test/docx/golden/block_quotes.docx +++ b/test/docx/golden/block_quotes.docx diff --git a/test/docx/golden/codeblock.docx b/test/docx/golden/codeblock.docx Binary files differindex 224c3c839..62c250088 100644 --- a/test/docx/golden/codeblock.docx +++ b/test/docx/golden/codeblock.docx diff --git a/test/docx/golden/comments.docx b/test/docx/golden/comments.docx Binary files differindex 79e19d04b..eec06b554 100644 --- a/test/docx/golden/comments.docx +++ b/test/docx/golden/comments.docx diff --git a/test/docx/golden/custom_style_no_reference.docx b/test/docx/golden/custom_style_no_reference.docx Binary files differindex 561fb1534..08fb23e35 100644 --- a/test/docx/golden/custom_style_no_reference.docx +++ b/test/docx/golden/custom_style_no_reference.docx diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx Binary files differindex b49f66856..e319402f2 100644 --- a/test/docx/golden/custom_style_preserve.docx +++ b/test/docx/golden/custom_style_preserve.docx diff --git a/test/docx/golden/custom_style_reference.docx b/test/docx/golden/custom_style_reference.docx Binary files differindex da579ca2f..4ff5e0d1f 100644 --- a/test/docx/golden/custom_style_reference.docx +++ b/test/docx/golden/custom_style_reference.docx diff --git a/test/docx/golden/definition_list.docx b/test/docx/golden/definition_list.docx Binary files differindex c1d06bc66..fda2f36ff 100644 --- a/test/docx/golden/definition_list.docx +++ b/test/docx/golden/definition_list.docx diff --git a/test/docx/golden/document-properties-short-desc.docx b/test/docx/golden/document-properties-short-desc.docx Binary files differindex b0d7b131f..bca089815 100644 --- a/test/docx/golden/document-properties-short-desc.docx +++ b/test/docx/golden/document-properties-short-desc.docx diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx Binary files differindex 152149d89..197edc2d8 100644 --- a/test/docx/golden/document-properties.docx +++ b/test/docx/golden/document-properties.docx diff --git a/test/docx/golden/headers.docx b/test/docx/golden/headers.docx Binary files differindex f3832437d..e8865a24e 100644 --- a/test/docx/golden/headers.docx +++ b/test/docx/golden/headers.docx diff --git a/test/docx/golden/image.docx b/test/docx/golden/image.docx Binary files differindex bbc632aea..6d6b4c9f3 100644 --- a/test/docx/golden/image.docx +++ b/test/docx/golden/image.docx diff --git a/test/docx/golden/inline_code.docx b/test/docx/golden/inline_code.docx Binary files differindex 51eb15567..61bd6ba80 100644 --- a/test/docx/golden/inline_code.docx +++ b/test/docx/golden/inline_code.docx diff --git a/test/docx/golden/inline_formatting.docx b/test/docx/golden/inline_formatting.docx Binary files differindex 78391faee..bfb3a110b 100644 --- a/test/docx/golden/inline_formatting.docx +++ b/test/docx/golden/inline_formatting.docx diff --git a/test/docx/golden/inline_images.docx b/test/docx/golden/inline_images.docx Binary files differindex f43dbd9bc..b73c35e2e 100644 --- a/test/docx/golden/inline_images.docx +++ b/test/docx/golden/inline_images.docx diff --git a/test/docx/golden/link_in_notes.docx b/test/docx/golden/link_in_notes.docx Binary files differindex ac1f91c9e..c6fb930af 100644 --- a/test/docx/golden/link_in_notes.docx +++ b/test/docx/golden/link_in_notes.docx diff --git a/test/docx/golden/links.docx b/test/docx/golden/links.docx Binary files differindex 2fc3a973b..93db9c769 100644 --- a/test/docx/golden/links.docx +++ b/test/docx/golden/links.docx diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx Binary files differindex 645d55ed9..d4d95b0a3 100644 --- a/test/docx/golden/lists.docx +++ b/test/docx/golden/lists.docx diff --git a/test/docx/golden/lists_continuing.docx b/test/docx/golden/lists_continuing.docx Binary files differindex e0c70ec8b..3d346262e 100644 --- a/test/docx/golden/lists_continuing.docx +++ b/test/docx/golden/lists_continuing.docx diff --git a/test/docx/golden/lists_div_bullets.docx b/test/docx/golden/lists_div_bullets.docx Binary files differindex e9830e2b4..3fdf638bb 100644 --- a/test/docx/golden/lists_div_bullets.docx +++ b/test/docx/golden/lists_div_bullets.docx diff --git a/test/docx/golden/lists_multiple_initial.docx b/test/docx/golden/lists_multiple_initial.docx Binary files differindex 43ecec97b..e374a5b64 100644 --- a/test/docx/golden/lists_multiple_initial.docx +++ b/test/docx/golden/lists_multiple_initial.docx diff --git a/test/docx/golden/lists_restarting.docx b/test/docx/golden/lists_restarting.docx Binary files differindex 9a996f345..a15f34504 100644 --- a/test/docx/golden/lists_restarting.docx +++ b/test/docx/golden/lists_restarting.docx diff --git a/test/docx/golden/nested_anchors_in_header.docx b/test/docx/golden/nested_anchors_in_header.docx Binary files differindex 2e6ba5048..5f586c7b5 100644 --- a/test/docx/golden/nested_anchors_in_header.docx +++ b/test/docx/golden/nested_anchors_in_header.docx diff --git a/test/docx/golden/notes.docx b/test/docx/golden/notes.docx Binary files differindex 1aee1887e..2fae1180c 100644 --- a/test/docx/golden/notes.docx +++ b/test/docx/golden/notes.docx diff --git a/test/docx/golden/raw-blocks.docx b/test/docx/golden/raw-blocks.docx Binary files differindex b654496af..faa83617a 100644 --- a/test/docx/golden/raw-blocks.docx +++ b/test/docx/golden/raw-blocks.docx diff --git a/test/docx/golden/raw-bookmarks.docx b/test/docx/golden/raw-bookmarks.docx Binary files differindex 4b159b79b..508a4b17b 100644 --- a/test/docx/golden/raw-bookmarks.docx +++ b/test/docx/golden/raw-bookmarks.docx diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx Binary files differindex 1f390bad3..26aa84e43 100644 --- a/test/docx/golden/table_one_row.docx +++ b/test/docx/golden/table_one_row.docx diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx Binary files differindex 47a169b39..acafc4e5e 100644 --- a/test/docx/golden/table_with_list_cell.docx +++ b/test/docx/golden/table_with_list_cell.docx diff --git a/test/docx/golden/tables-default-widths.docx b/test/docx/golden/tables-default-widths.docx Binary files differindex d1b4b9359..8a8bde8b7 100644 --- a/test/docx/golden/tables-default-widths.docx +++ b/test/docx/golden/tables-default-widths.docx diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx Binary files differindex 6de810420..a5d11c27c 100644 --- a/test/docx/golden/tables.docx +++ b/test/docx/golden/tables.docx diff --git a/test/docx/golden/tables_separated_with_rawblock.docx b/test/docx/golden/tables_separated_with_rawblock.docx Binary files differindex 90727c06e..1085a0949 100644 --- a/test/docx/golden/tables_separated_with_rawblock.docx +++ b/test/docx/golden/tables_separated_with_rawblock.docx diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx Binary files differindex 77ce29a8c..41d26562d 100644 --- a/test/docx/golden/track_changes_deletion.docx +++ b/test/docx/golden/track_changes_deletion.docx diff --git a/test/docx/golden/track_changes_insertion.docx b/test/docx/golden/track_changes_insertion.docx Binary files differindex 27a36ed6e..3e0380049 100644 --- a/test/docx/golden/track_changes_insertion.docx +++ b/test/docx/golden/track_changes_insertion.docx diff --git a/test/docx/golden/track_changes_move.docx b/test/docx/golden/track_changes_move.docx Binary files differindex 93141cf25..ee83709c9 100644 --- a/test/docx/golden/track_changes_move.docx +++ b/test/docx/golden/track_changes_move.docx diff --git a/test/docx/golden/track_changes_scrubbed_metadata.docx b/test/docx/golden/track_changes_scrubbed_metadata.docx Binary files differindex 9864ca04d..f3b12bfad 100644 --- a/test/docx/golden/track_changes_scrubbed_metadata.docx +++ b/test/docx/golden/track_changes_scrubbed_metadata.docx diff --git a/test/docx/golden/unicode.docx b/test/docx/golden/unicode.docx Binary files differindex e08c9ffd6..c118c7ebd 100644 --- a/test/docx/golden/unicode.docx +++ b/test/docx/golden/unicode.docx diff --git a/test/docx/golden/verbatim_subsuper.docx b/test/docx/golden/verbatim_subsuper.docx Binary files differindex adf72b847..5388d126c 100644 --- a/test/docx/golden/verbatim_subsuper.docx +++ b/test/docx/golden/verbatim_subsuper.docx |
