@@ -486,12 +486,15 @@ archiveToComments zf =
486486 Just c -> Comments cmts_namespaces c
487487 Nothing -> Comments cmts_namespaces M.empty
488488
489−filePathToRelType :: FilePath -> Maybe DocumentLocation
490−filePathToRelType "word/_rels/document.xml.rels" = Just InDocument
491−filePathToRelType "word/_rels/document2.xml.rels" = Just InDocument
492−filePathToRelType "word/_rels/footnotes.xml.rels" = Just InFootnote
493−filePathToRelType "word/_rels/endnotes.xml.rels" = Just InEndnote
494−filePathToRelType _ = Nothing
489+filePathToRelType :: FilePath -> FilePath -> Maybe DocumentLocation
490+filePathToRelType "word/_rels/footnotes.xml.rels" _ = Just InFootnote
491+filePathToRelType "word/_rels/endnotes.xml.rels" _ = Just InEndnote
492+-- -- to see if it's a documentPath, we have to check against the dynamic
493+-- -- docPath specified in "_rels/.rels"
494+filePathToRelType path docXmlPath =
495+ if path == "word/_rels/" ++ (takeFileName docXmlPath) ++ ".rels"
496+ then Just InDocument
497+ else Nothing
495498
496499relElemToRelationship :: DocumentLocation -> Element -> Maybe Relationship
497500relElemToRelationship relType element | qName (elName element) == "Relationship" =
@@ -501,16 +504,20 @@ relElemToRelationship relType element | qName (elName element) == "Relationship"
501504 return $ Relationship relType relId target
502505relElemToRelationship _ _ = Nothing
503506
504−filePathToRelationships :: Archive -> FilePath -> [Relationship]
505−filePathToRelationships ar fp | Just relType <- filePathToRelType fp
506− , Just entry <- findEntryByPath fp ar
507− , Just relElems <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry =
507+filePathToRelationships :: Archive -> (Maybe FilePath) -> FilePath -> [Relationship]
508+filePathToRelationships ar mDocXmlPath fp
509+ | Just docXmlPath <- mDocXmlPath
510+ , Just relType <- filePathToRelType fp docXmlPath
511+ , Just entry <- findEntryByPath fp ar
512+ , Just relElems <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry =
508513 mapMaybe (relElemToRelationship relType) $ elChildren relElems
509−filePathToRelationships _ _ = []
514+filePathToRelationships _ _ _ = []
510515
511516archiveToRelationships :: Archive -> [Relationship]
512517archiveToRelationships archive =
513− concatMap (filePathToRelationships archive) $ filesInArchive archive
518+ let mDocXmlPath = getDocumentPath archive
519+ in
520+ concatMap (filePathToRelationships archive mDocXmlPath) $ filesInArchive archive
514521
515522filePathIsMedia :: FilePath -> Bool
516523filePathIsMedia fp =