@@ -217,7 +217,7 @@ writeDocx opts doc@(Pandoc meta _) = do
217217 -- styles
218218 let newstyles = styleToOpenXml $ writerHighlightStyle opts
219219 let stylepath = "word/styles.xml"
220− styledoc <- parseXml refArchive stylepath
220+ styledoc <- parseXml refArchive stylepath Nothing
221221 let styledoc' = styledoc{ elContent = elContent styledoc ++
222222 [Elem x | x <- newstyles, writerHighlight opts] }
223223 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
@@ -256,19 +256,20 @@ writeDocx opts doc@(Pandoc meta _) = do
256256 ]
257257 let relsEntry = toEntry relsPath epochtime $ renderXml rels
258258
259− let entryFromArchive path = (toEntry path epochtime . renderXml) `fmap`
260− parseXml refArchive path
261− docPropsAppEntry <- entryFromArchive "docProps/app.xml"
262− themeEntry <- entryFromArchive "word/theme/theme1.xml"
263− fontTableEntry <- entryFromArchive "word/fontTable.xml"
264− settingsEntry <- entryFromArchive "word/settings.xml"
265− webSettingsEntry <- entryFromArchive "word/webSettings.xml"
259+ let entryFromArchive path fallback =
260+ (toEntry path epochtime . renderXml) `fmap`
261+ parseXml refArchive path fallback
262+ docPropsAppEntry <- entryFromArchive "docProps/app.xml" Nothing
263+ themeEntry <- entryFromArchive "word/theme/theme1.xml" Nothing
264+ fontTableEntry <- entryFromArchive "word/fontTable.xml" Nothing
265+ settingsEntry <- entryFromArchive "word/settings.xml" Nothing
266+ webSettingsEntry <- entryFromArchive "word/webSettings.xml" Nothing
266267 let miscRels = [ f | f <- filesInArchive refArchive
267268 , "word/_rels/" `isPrefixOf` f
268269 , ".xml.rels" `isSuffixOf` f
269270 , f /= "word/_rels/document.xml.rels"
270271 , f /= "word/_rels/footnotes.xml.rels" ]
271− miscRelEntries <- mapM entryFromArchive miscRels
272+ miscRelEntries <- mapM (\f -> entryFromArchive f Nothing) miscRels
272273
273274 -- Create archive
274275 let archive = foldr addEntryToArchive emptyArchive $
@@ -814,10 +815,10 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
814815br :: Element
815816br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
816817
817−parseXml :: Archive -> String -> IO Element
818−parseXml refArchive relpath =
819− case findEntryByPath relpath refArchive of
820− Just e -> case parseXMLDoc $ UTF8.toStringLazy $ fromEntry e of
821− Just d -> return d
822− Nothing -> fail $ relpath ++ " corrupt in reference docx"
823− Nothing -> fail $ relpath ++ " missing in reference docx"
818+parseXml :: Archive -> String -> Maybe String -> IO Element
819+parseXml refArchive relpath fallback =
820+ case (findEntryByPath relpath refArchive
821+ >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) `mplus`
822+ (fallback >>= parseXMLDoc) of
823+ Just d -> return d
824+ Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"