@@ -30,7 +30,7 @@ Conversion of 'Pandoc' documents to docx.
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
32import Data.Maybe (fromMaybe)
32import Data.Maybe (fromMaybe)
33−import Data.List ( intercalate, isPrefixOf )
33+import Data.List ( intercalate, isPrefixOf, isSuffixOf )
34import qualified Data.ByteString as B
34import qualified Data.ByteString as B
35import qualified Data.ByteString.Lazy as BL
35import qualified Data.ByteString.Lazy as BL
36import qualified Data.ByteString.Lazy.Char8 as BL8
36import qualified Data.ByteString.Lazy.Char8 as BL8
@@ -265,6 +265,7 @@ writeDocx opts doc@(Pandoc meta _) = do
265 webSettingsEntry <- entryFromArchive "word/webSettings.xml"
265 webSettingsEntry <- entryFromArchive "word/webSettings.xml"
266 let miscRels = [ f | f <- filesInArchive refArchive
266 let miscRels = [ f | f <- filesInArchive refArchive
267 , "word/_rels/" `isPrefixOf` f
267 , "word/_rels/" `isPrefixOf` f
268+ , ".xml.rels" `isSuffixOf` f
268 , f /= "word/_rels/document.xml.rels"
269 , f /= "word/_rels/document.xml.rels"
269 , f /= "word/_rels/footnotes.xml.rels" ]
270 , f /= "word/_rels/footnotes.xml.rels" ]
270 miscRelEntries <- mapM entryFromArchive miscRels
271 miscRelEntries <- mapM entryFromArchive miscRels
@@ -815,6 +816,8 @@ br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
816parseXml :: Archive -> String -> IO Element
817parseXml :: Archive -> String -> IO Element
817parseXml refArchive relpath =
818parseXml refArchive relpath =
818− case (findEntryByPath relpath refArchive >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
819+ case findEntryByPath relpath refArchive of
820+ Just e -> case parseXMLDoc $ UTF8.toStringLazy $ fromEntry e of
819− Just d -> return d
821+ Just d -> return d
822+ Nothing -> fail $ relpath ++ " corrupt in reference docx"
820 Nothing -> fail $ relpath ++ " missing in reference docx"
823 Nothing -> fail $ relpath ++ " missing in reference docx"