From 30033f417f3009eb8c4b5fa8302cea7fecad48ee Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 9 Oct 2018 10:38:50 -0700 Subject: Docx writer: added framework for custom properties. So far, we don't actually write any custom properties, but we have the infrastructure to add this. See #3034. --- data/docx/[Content_Types].xml | 2 +- data/docx/_rels/.rels | 3 ++- data/docx/docProps/custom.xml | 2 ++ src/Text/Pandoc/Class.hs | 1 + src/Text/Pandoc/Writers/Docx.hs | 21 ++++++++++++++++++++- test/docx/golden/block_quotes.docx | Bin 9778 -> 10147 bytes test/docx/golden/codeblock.docx | Bin 9638 -> 10007 bytes test/docx/golden/comments.docx | Bin 9960 -> 10328 bytes test/docx/golden/custom_style_no_reference.docx | Bin 9724 -> 10092 bytes test/docx/golden/custom_style_reference.docx | Bin 12118 -> 12486 bytes test/docx/golden/definition_list.docx | Bin 9617 -> 9986 bytes test/docx/golden/headers.docx | Bin 9765 -> 10134 bytes test/docx/golden/image.docx | Bin 26452 -> 26810 bytes test/docx/golden/inline_code.docx | Bin 9560 -> 9929 bytes test/docx/golden/inline_formatting.docx | Bin 9747 -> 10115 bytes test/docx/golden/inline_images.docx | Bin 26506 -> 26865 bytes test/docx/golden/link_in_notes.docx | Bin 9781 -> 10150 bytes test/docx/golden/links.docx | Bin 9960 -> 10329 bytes test/docx/golden/lists.docx | Bin 10031 -> 10400 bytes test/docx/golden/lists_continuing.docx | Bin 9830 -> 10199 bytes test/docx/golden/lists_restarting.docx | Bin 9830 -> 10199 bytes test/docx/golden/nested_anchors_in_header.docx | Bin 9882 -> 10251 bytes test/docx/golden/notes.docx | Bin 9731 -> 10100 bytes test/docx/golden/table_one_row.docx | Bin 9581 -> 9950 bytes test/docx/golden/table_with_list_cell.docx | Bin 9948 -> 10317 bytes test/docx/golden/tables.docx | Bin 9963 -> 10332 bytes test/docx/golden/track_changes_deletion.docx | Bin 9604 -> 9973 bytes test/docx/golden/track_changes_insertion.docx | Bin 9587 -> 9956 bytes test/docx/golden/track_changes_move.docx | Bin 9621 -> 9990 bytes test/docx/golden/unicode.docx | Bin 9545 -> 9914 bytes test/docx/golden/verbatim_subsuper.docx | Bin 9593 -> 9962 bytes 31 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 data/docx/docProps/custom.xml diff --git a/data/docx/[Content_Types].xml b/data/docx/[Content_Types].xml index 1e888dff9..0c0118a88 100644 --- a/data/docx/[Content_Types].xml +++ b/data/docx/[Content_Types].xml @@ -1,2 +1,2 @@ - + diff --git a/data/docx/_rels/.rels b/data/docx/_rels/.rels index 44e5daa3d..1121ed8d2 100644 --- a/data/docx/_rels/.rels +++ b/data/docx/_rels/.rels @@ -1,2 +1,3 @@ - \ No newline at end of file + + diff --git a/data/docx/docProps/custom.xml b/data/docx/docProps/custom.xml new file mode 100644 index 000000000..bdd0df8dd --- /dev/null +++ b/data/docx/docProps/custom.xml @@ -0,0 +1,2 @@ + + diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index e47546dfc..92b41aa4e 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -629,6 +629,7 @@ getDefaultReferenceDocx = do "_rels/.rels", "docProps/app.xml", "docProps/core.xml", + "docProps/custom.xml", "word/document.xml", "word/fontTable.xml", "word/footnotes.xml", diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 6ff38535b..d80b4a7bc 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -349,6 +349,8 @@ writeDocx opts doc@(Pandoc meta _) = do "application/vnd.openxmlformats-officedocument.extended-properties+xml") ,("/docProps/core.xml", "application/vnd.openxmlformats-package.core-properties+xml") + ,("/docProps/custom.xml", + "application/vnd.openxmlformats-officedocument.custom-properties+xml") ,("/word/styles.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml") ,("/word/document.xml", @@ -507,6 +509,19 @@ writeDocx opts doc@(Pandoc meta _) = do ]) (formatTime defaultTimeLocale "%FT%XZ" utctime) let docPropsEntry = toEntry docPropsPath epochtime $ renderXml docProps + let customProperties :: [(String, String)] + customProperties = [] -- FIXME + let mkCustomProp (k, v) pid = mknode "property" + [("fmtid","{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") + ,("pid", show pid) + ,("name", k)] $ mknode "vt:lpwstr" [] v + let customPropsPath = "docProps/custom.xml" + let customProps = mknode "Properties" + [("xmlns","http://schemas.openxmlformats.org/officeDocument/2006/custom-properties") + ,("xmlns:vt","http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes") + ] $ zipWith mkCustomProp customProperties [(2 :: Int)..] + let customPropsEntry = toEntry customPropsPath epochtime $ renderXml customProps + let relsPath = "_rels/.rels" let rels = mknode "Relationships" [("xmlns", "http://schemas.openxmlformats.org/package/2006/relationships")] $ map (\attrs -> mknode "Relationship" attrs ()) @@ -519,6 +534,9 @@ writeDocx opts doc@(Pandoc meta _) = do , [("Id","rId3") ,("Type","http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties") ,("Target","docProps/core.xml")] + , [("Id","rId5") + ,("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties") + ,("Target","docProps/custom.xml")] ] let relsEntry = toEntry relsPath epochtime $ renderXml rels @@ -558,7 +576,8 @@ writeDocx opts doc@(Pandoc meta _) = do contentTypesEntry : relsEntry : contentEntry : relEntry : footnoteRelEntry : numEntry : styleEntry : footnotesEntry : commentsEntry : - docPropsEntry : docPropsAppEntry : themeEntry : + docPropsEntry : docPropsAppEntry : customPropsEntry : + themeEntry : fontTableEntry : settingsEntry : webSettingsEntry : imageEntries ++ headerFooterEntries ++ miscRelEntries ++ otherMediaEntries diff --git a/test/docx/golden/block_quotes.docx b/test/docx/golden/block_quotes.docx index 28d6f035e..d118a6fb0 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 af85598dc..7068893c1 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 33831dc06..2cdf4c210 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 78f56893c..f7e332963 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_reference.docx b/test/docx/golden/custom_style_reference.docx index dfc2c960b..44900181e 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 c3f076387..b57686e7d 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/headers.docx b/test/docx/golden/headers.docx index c2b6206a3..a51443929 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 95a28a098..e1f043ca3 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 1d415e411..46a3a6172 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 9e07bd25d..c214c7eda 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 62c5943ba..6ae175e4f 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 c86f9aecd..7376966b3 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 652a93569..d5839c517 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 5e900feb1..bcc5e706d 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 278edaa99..bd35f2887 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_restarting.docx b/test/docx/golden/lists_restarting.docx index 112b824b5..f693fca6f 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 c2a10b828..20f83b3ca 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 c6093c18a..197ccff94 100644 Binary files a/test/docx/golden/notes.docx and b/test/docx/golden/notes.docx differ diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx index 34de65e2e..ace98df83 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 c27f99736..fef0b16f5 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.docx b/test/docx/golden/tables.docx index 4fcdd73c3..ec73cfeef 100644 Binary files a/test/docx/golden/tables.docx and b/test/docx/golden/tables.docx differ diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx index 7b404dba1..dab2c3170 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 500a7c239..7b5af8ed5 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 05705c040..666cd85eb 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/unicode.docx b/test/docx/golden/unicode.docx index c1626874d..ef9480059 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 d2ada67fa..dc9453430 100644 Binary files a/test/docx/golden/verbatim_subsuper.docx and b/test/docx/golden/verbatim_subsuper.docx differ -- cgit v1.2.3