git.iko.soy/typeable/pandoc
on master help sign in
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.

commit5cfec4b9224462524040aae8312e3b3e61cbf422 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 11 Feb 2012, 09:12 (15 years ago) parentfdb11cd
1 file changed+10−1
src/Text/Pandoc/Writers/Docx.hs+10−1
src/Text/Pandoc/Writers/Docx.hs+10−1
@@ -166,8 +166,17 @@ writeDocx mbRefDocx opts doc@(Pandoc (Meta tit auths date) _) = do
166166 : mknode "dcterms:modified" [("xsi:type","dcterms:W3CDTF")] () -- put current time here
167167 : map (mknode "dc:creator" [] . stringify) auths
168168 let docPropsEntry = toEntry docPropsPath epochtime $ fromString $ showTopElement' docProps
169+ let relsPath = "_rels/.rels"
170+ rels <- case findEntryByPath relsPath refArchive of
171+ Just e -> return $ toString $ fromEntry e
172+ Nothing -> err 57 "could not find .rels/_rels in reference docx"
173+ -- fix .rels/_rels, which can get screwed up when reference.docx is edited by Word
174+ let rels' = substitute "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
175+ "http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties"
176+ rels
177+ let relsEntry = toEntry relsPath epochtime $ fromString rels'
169178 let archive = foldr addEntryToArchive refArchive $
170− contentEntry : relEntry : numEntry : styleEntry : docPropsEntry : imageEntries
179+ relsEntry : contentEntry : relEntry : numEntry : styleEntry : docPropsEntry : imageEntries
171180 return $ fromArchive archive
172181
173182styleToOpenXml :: Style -> [Element]