From 5cfec4b9224462524040aae8312e3b3e61cbf422 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 11 Feb 2012 09:12:58 -0800 Subject: Fix _rels/.rels if it has been screwed up by Word. Closes #414. Previously, if you edited the reference.docx with Word, then created a new docx using the edited reference.docx, Word would complain about the file being corrupt. The problem seems to be that Word changes _rels/.rels, changing the Type of the Relationship to docProps/core.xml from "http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties" to "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties". As far as I can see, this is a bug in Word, since the latter is not valid. (See http://idippedut.dk/post/2010/04/22/Correct-according-to-spec-or-implementation.aspx.) This change simply does a global replace on _rels/.rels that reverts the change Word makes. And now producing docx files with Word-modified reference.docx seems to work. --- src/Text/Pandoc/Writers/Docx.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index f29a0fe42..22278be7e 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -166,8 +166,17 @@ writeDocx mbRefDocx opts doc@(Pandoc (Meta tit auths date) _) = do : mknode "dcterms:modified" [("xsi:type","dcterms:W3CDTF")] () -- put current time here : map (mknode "dc:creator" [] . stringify) auths let docPropsEntry = toEntry docPropsPath epochtime $ fromString $ showTopElement' docProps + let relsPath = "_rels/.rels" + rels <- case findEntryByPath relsPath refArchive of + Just e -> return $ toString $ fromEntry e + Nothing -> err 57 "could not find .rels/_rels in reference docx" + -- fix .rels/_rels, which can get screwed up when reference.docx is edited by Word + let rels' = substitute "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" + "http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties" + rels + let relsEntry = toEntry relsPath epochtime $ fromString rels' let archive = foldr addEntryToArchive refArchive $ - contentEntry : relEntry : numEntry : styleEntry : docPropsEntry : imageEntries + relsEntry : contentEntry : relEntry : numEntry : styleEntry : docPropsEntry : imageEntries return $ fromArchive archive styleToOpenXml :: Style -> [Element] -- cgit v1.2.3