@@ -92,6 +92,7 @@ data ReaderEnv = ReaderEnv { envNotes :: Notes
9292 , envCharStyles :: CharStyleMap
9393 , envParStyles :: ParStyleMap
9494 , envLocation :: DocumentLocation
95+ , envDocXmlPath :: FilePath
9596 }
9697 deriving Show
9798
@@ -343,14 +344,26 @@ archiveToDocx archive = fst <$> archiveToDocxWithWarnings archive
343344
344345archiveToDocxWithWarnings :: Archive -> Either DocxError (Docx, [String])
345346archiveToDocxWithWarnings archive = do
347+ docXmlPath <- case getDocumentXmlPath archive of
348+ Just fp -> Right fp
349+ Nothing -> Left DocxError
346350 let notes = archiveToNotes archive
347351 comments = archiveToComments archive
348352 numbering = archiveToNumbering archive
349− rels = archiveToRelationships archive
353+ rels = archiveToRelationships archive docXmlPath
350354 media = filteredFilesFromArchive archive filePathIsMedia
351355 (styles, parstyles) = archiveToStyles archive
352− rEnv =
353− ReaderEnv notes comments numbering rels media Nothing styles parstyles InDocument
356+ rEnv = ReaderEnv { envNotes = notes
357+ , envComments = comments
358+ , envNumbering = numbering
359+ , envRelationships = rels
360+ , envMedia = media
361+ , envFont = Nothing
362+ , envCharStyles = styles
363+ , envParStyles = parstyles
364+ , envLocation = InDocument
365+ , envDocXmlPath = docXmlPath
366+ }
354367 rState = ReaderState { stateWarnings = []
355368 , stateFldCharState = FldCharClosed
356369 }
@@ -359,8 +372,8 @@ archiveToDocxWithWarnings archive = do
359372 Right doc -> Right (Docx doc, stateWarnings st)
360373 Left e -> Left e
361374
362−getDocumentPath :: Archive -> Maybe String
363−getDocumentPath zf = do
375+getDocumentXmlPath :: Archive -> Maybe String
376+getDocumentXmlPath zf = do
364377 entry <- findEntryByPath "_rels/.rels" zf
365378 relsElem <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry
366379 let rels = filterChildrenName (\n -> qName n == "Relationship") relsElem
@@ -372,7 +385,7 @@ getDocumentPath zf = do
372385
373386archiveToDocument :: Archive -> D Document
374387archiveToDocument zf = do
375− docPath <- maybeToD $ getDocumentPath zf
388+ docPath <- asks envDocXmlPath
376389 entry <- maybeToD $ findEntryByPath docPath zf
377390 docElem <- maybeToD $ (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry
378391 let namespaces = elemToNameSpaces docElem
@@ -504,20 +517,17 @@ relElemToRelationship relType element | qName (elName element) == "Relationship"
504517 return $ Relationship relType relId target
505518relElemToRelationship _ _ = Nothing
506519
507−filePathToRelationships :: Archive -> (Maybe FilePath) -> FilePath -> [Relationship]
508−filePathToRelationships ar mDocXmlPath fp
509− | Just docXmlPath <- mDocXmlPath
510− , Just relType <- filePathToRelType fp docXmlPath
520+filePathToRelationships :: Archive -> FilePath -> FilePath -> [Relationship]
521+filePathToRelationships ar docXmlPath fp
522+ | Just relType <- filePathToRelType fp docXmlPath
511523 , Just entry <- findEntryByPath fp ar
512524 , Just relElems <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry =
513525 mapMaybe (relElemToRelationship relType) $ elChildren relElems
514526filePathToRelationships _ _ _ = []
515527
516−archiveToRelationships :: Archive -> [Relationship]
517−archiveToRelationships archive =
518− let mDocXmlPath = getDocumentPath archive
519− in
520− concatMap (filePathToRelationships archive mDocXmlPath) $ filesInArchive archive
528+archiveToRelationships :: Archive -> FilePath -> [Relationship]
529+archiveToRelationships archive docXmlPath =
530+ concatMap (filePathToRelationships archive docXmlPath) $ filesInArchive archive
521531
522532filePathIsMedia :: FilePath -> Bool
523533filePathIsMedia fp =