diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-02-11 09:12:58 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-02-11 09:12:58 -0800 |
commit | 5cfec4b9224462524040aae8312e3b3e61cbf422 (patch) | |
tree | d6cd57a01842f94a2e3944b2d5a9191879af9404 /src/Text/Pandoc | |
parent | fdb11cdae90317a9892b0b5f9b66ab985f82b019 (diff) | |
download | pandoc-5cfec4b9224462524040aae8312e3b3e61cbf422.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 11 |
1 files changed, 10 insertions, 1 deletions
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] |