diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 1a2cc79a4eea..e89ec48018bc 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 index 2c00e9ef0ec0..e1e296f9ea73 100644 Binary files a/test/docx/golden/block_quotes.docx and b/test/docx/golden/block_quotes.docx differ diff --git a/test/docx/golden/codeblock.docx b/test/docx/golden/codeblock.docx index 224c3c839bb9..62c2500885ad 100644 Binary files a/test/docx/golden/codeblock.docx and b/test/docx/golden/codeblock.docx differ diff --git a/test/docx/golden/comments.docx b/test/docx/golden/comments.docx index 79e19d04b260..eec06b5542f8 100644 Binary files a/test/docx/golden/comments.docx and b/test/docx/golden/comments.docx differ diff --git a/test/docx/golden/custom_style_no_reference.docx b/test/docx/golden/custom_style_no_reference.docx index 561fb1534657..08fb23e353b9 100644 Binary files a/test/docx/golden/custom_style_no_reference.docx and b/test/docx/golden/custom_style_no_reference.docx differ diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx index b49f668568d8..e319402f20ae 100644 Binary files a/test/docx/golden/custom_style_preserve.docx and b/test/docx/golden/custom_style_preserve.docx differ diff --git a/test/docx/golden/custom_style_reference.docx b/test/docx/golden/custom_style_reference.docx index da579ca2ffcb..4ff5e0d1f665 100644 Binary files a/test/docx/golden/custom_style_reference.docx and b/test/docx/golden/custom_style_reference.docx differ diff --git a/test/docx/golden/definition_list.docx b/test/docx/golden/definition_list.docx index c1d06bc66aad..fda2f36ff432 100644 Binary files a/test/docx/golden/definition_list.docx and b/test/docx/golden/definition_list.docx differ diff --git a/test/docx/golden/document-properties-short-desc.docx b/test/docx/golden/document-properties-short-desc.docx index b0d7b131f46f..bca089815b3c 100644 Binary files a/test/docx/golden/document-properties-short-desc.docx and b/test/docx/golden/document-properties-short-desc.docx differ diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx index 152149d89f8e..197edc2d8b5e 100644 Binary files a/test/docx/golden/document-properties.docx and b/test/docx/golden/document-properties.docx differ diff --git a/test/docx/golden/headers.docx b/test/docx/golden/headers.docx index f3832437d464..e8865a24e250 100644 Binary files a/test/docx/golden/headers.docx and b/test/docx/golden/headers.docx differ diff --git a/test/docx/golden/image.docx b/test/docx/golden/image.docx index bbc632aea889..6d6b4c9f3d1e 100644 Binary files a/test/docx/golden/image.docx and b/test/docx/golden/image.docx differ diff --git a/test/docx/golden/inline_code.docx b/test/docx/golden/inline_code.docx index 51eb155677cb..61bd6ba807b8 100644 Binary files a/test/docx/golden/inline_code.docx and b/test/docx/golden/inline_code.docx differ diff --git a/test/docx/golden/inline_formatting.docx b/test/docx/golden/inline_formatting.docx index 78391faeeceb..bfb3a110be5a 100644 Binary files a/test/docx/golden/inline_formatting.docx and b/test/docx/golden/inline_formatting.docx differ diff --git a/test/docx/golden/inline_images.docx b/test/docx/golden/inline_images.docx index f43dbd9bc14e..b73c35e2e6d7 100644 Binary files a/test/docx/golden/inline_images.docx and b/test/docx/golden/inline_images.docx differ diff --git a/test/docx/golden/link_in_notes.docx b/test/docx/golden/link_in_notes.docx index ac1f91c9eff4..c6fb930af9e5 100644 Binary files a/test/docx/golden/link_in_notes.docx and b/test/docx/golden/link_in_notes.docx differ diff --git a/test/docx/golden/links.docx b/test/docx/golden/links.docx index 2fc3a973b5d3..93db9c7696c9 100644 Binary files a/test/docx/golden/links.docx and b/test/docx/golden/links.docx differ diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx index 645d55ed92df..d4d95b0a3d87 100644 Binary files a/test/docx/golden/lists.docx and b/test/docx/golden/lists.docx differ diff --git a/test/docx/golden/lists_continuing.docx b/test/docx/golden/lists_continuing.docx index e0c70ec8b811..3d346262e346 100644 Binary files a/test/docx/golden/lists_continuing.docx and b/test/docx/golden/lists_continuing.docx differ diff --git a/test/docx/golden/lists_div_bullets.docx b/test/docx/golden/lists_div_bullets.docx index e9830e2b45bd..3fdf638bbce4 100644 Binary files a/test/docx/golden/lists_div_bullets.docx and b/test/docx/golden/lists_div_bullets.docx differ diff --git a/test/docx/golden/lists_multiple_initial.docx b/test/docx/golden/lists_multiple_initial.docx index 43ecec97b610..e374a5b6476e 100644 Binary files a/test/docx/golden/lists_multiple_initial.docx and b/test/docx/golden/lists_multiple_initial.docx differ diff --git a/test/docx/golden/lists_restarting.docx b/test/docx/golden/lists_restarting.docx index 9a996f345109..a15f34504fb8 100644 Binary files a/test/docx/golden/lists_restarting.docx and b/test/docx/golden/lists_restarting.docx differ diff --git a/test/docx/golden/nested_anchors_in_header.docx b/test/docx/golden/nested_anchors_in_header.docx index 2e6ba5048b03..5f586c7b5486 100644 Binary files a/test/docx/golden/nested_anchors_in_header.docx and b/test/docx/golden/nested_anchors_in_header.docx differ diff --git a/test/docx/golden/notes.docx b/test/docx/golden/notes.docx index 1aee1887eae8..2fae1180c060 100644 Binary files a/test/docx/golden/notes.docx and b/test/docx/golden/notes.docx differ diff --git a/test/docx/golden/raw-blocks.docx b/test/docx/golden/raw-blocks.docx index b654496af392..faa83617a9e6 100644 Binary files a/test/docx/golden/raw-blocks.docx and b/test/docx/golden/raw-blocks.docx differ diff --git a/test/docx/golden/raw-bookmarks.docx b/test/docx/golden/raw-bookmarks.docx index 4b159b79be7f..508a4b17b0d4 100644 Binary files a/test/docx/golden/raw-bookmarks.docx and b/test/docx/golden/raw-bookmarks.docx differ diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx index 1f390bad3bce..26aa84e43bac 100644 Binary files a/test/docx/golden/table_one_row.docx and b/test/docx/golden/table_one_row.docx differ diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx index 47a169b39210..acafc4e5e947 100644 Binary files a/test/docx/golden/table_with_list_cell.docx and b/test/docx/golden/table_with_list_cell.docx differ diff --git a/test/docx/golden/tables-default-widths.docx b/test/docx/golden/tables-default-widths.docx index d1b4b9359d28..8a8bde8b7d7f 100644 Binary files a/test/docx/golden/tables-default-widths.docx and b/test/docx/golden/tables-default-widths.docx differ diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx index 6de8104208b5..a5d11c27cd2f 100644 Binary files a/test/docx/golden/tables.docx and b/test/docx/golden/tables.docx differ diff --git a/test/docx/golden/tables_separated_with_rawblock.docx b/test/docx/golden/tables_separated_with_rawblock.docx index 90727c06ece3..1085a09498ec 100644 Binary files a/test/docx/golden/tables_separated_with_rawblock.docx and b/test/docx/golden/tables_separated_with_rawblock.docx differ diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx index 77ce29a8c361..41d26562dece 100644 Binary files a/test/docx/golden/track_changes_deletion.docx and b/test/docx/golden/track_changes_deletion.docx differ diff --git a/test/docx/golden/track_changes_insertion.docx b/test/docx/golden/track_changes_insertion.docx index 27a36ed6e899..3e0380049adc 100644 Binary files a/test/docx/golden/track_changes_insertion.docx and b/test/docx/golden/track_changes_insertion.docx differ diff --git a/test/docx/golden/track_changes_move.docx b/test/docx/golden/track_changes_move.docx index 93141cf25f95..ee83709c9253 100644 Binary files a/test/docx/golden/track_changes_move.docx and b/test/docx/golden/track_changes_move.docx differ diff --git a/test/docx/golden/track_changes_scrubbed_metadata.docx b/test/docx/golden/track_changes_scrubbed_metadata.docx index 9864ca04d09f..f3b12bfad81c 100644 Binary files a/test/docx/golden/track_changes_scrubbed_metadata.docx and b/test/docx/golden/track_changes_scrubbed_metadata.docx differ diff --git a/test/docx/golden/unicode.docx b/test/docx/golden/unicode.docx index e08c9ffd65bb..c118c7ebd670 100644 Binary files a/test/docx/golden/unicode.docx and b/test/docx/golden/unicode.docx differ diff --git a/test/docx/golden/verbatim_subsuper.docx b/test/docx/golden/verbatim_subsuper.docx index adf72b84770f..5388d126cef2 100644 Binary files a/test/docx/golden/verbatim_subsuper.docx and b/test/docx/golden/verbatim_subsuper.docx differ