aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2019-02-07 05:37:50 -0500
committerJesse Rosenthal <jrosenthal@jhu.edu>2019-02-07 06:00:37 -0500
commit9ff40429323056e88bd31c4cf73e5d8420548f1c (patch)
tree27ef658ce9b1717ec0286303ab4d8e18d6126755 /src
parent713ed7c0c5a6f64348f30d02d7baee0e46ef371c (diff)
downloadpandoc-9ff40429323056e88bd31c4cf73e5d8420548f1c.tar.gz
Docx reader: Extend dynamic xml location to detecting relationships
Getting the location used to depend on a hard-coded .rels file based on "word/document.xml". We now dynamically detect that file based on the document.xml file specified in "_rels/.rels"
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index fa4dc90a6..2c549bac0 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -486,12 +486,15 @@ archiveToComments zf =
Just c -> Comments cmts_namespaces c
Nothing -> Comments cmts_namespaces M.empty
-filePathToRelType :: FilePath -> Maybe DocumentLocation
-filePathToRelType "word/_rels/document.xml.rels" = Just InDocument
-filePathToRelType "word/_rels/document2.xml.rels" = Just InDocument
-filePathToRelType "word/_rels/footnotes.xml.rels" = Just InFootnote
-filePathToRelType "word/_rels/endnotes.xml.rels" = Just InEndnote
-filePathToRelType _ = Nothing
+filePathToRelType :: FilePath -> FilePath -> Maybe DocumentLocation
+filePathToRelType "word/_rels/footnotes.xml.rels" _ = Just InFootnote
+filePathToRelType "word/_rels/endnotes.xml.rels" _ = Just InEndnote
+-- -- to see if it's a documentPath, we have to check against the dynamic
+-- -- docPath specified in "_rels/.rels"
+filePathToRelType path docXmlPath =
+ if path == "word/_rels/" ++ (takeFileName docXmlPath) ++ ".rels"
+ then Just InDocument
+ else Nothing
relElemToRelationship :: DocumentLocation -> Element -> Maybe Relationship
relElemToRelationship relType element | qName (elName element) == "Relationship" =
@@ -501,16 +504,20 @@ relElemToRelationship relType element | qName (elName element) == "Relationship"
return $ Relationship relType relId target
relElemToRelationship _ _ = Nothing
-filePathToRelationships :: Archive -> FilePath -> [Relationship]
-filePathToRelationships ar fp | Just relType <- filePathToRelType fp
- , Just entry <- findEntryByPath fp ar
- , Just relElems <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry =
+filePathToRelationships :: Archive -> (Maybe FilePath) -> FilePath -> [Relationship]
+filePathToRelationships ar mDocXmlPath fp
+ | Just docXmlPath <- mDocXmlPath
+ , Just relType <- filePathToRelType fp docXmlPath
+ , Just entry <- findEntryByPath fp ar
+ , Just relElems <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry =
mapMaybe (relElemToRelationship relType) $ elChildren relElems
-filePathToRelationships _ _ = []
+filePathToRelationships _ _ _ = []
archiveToRelationships :: Archive -> [Relationship]
archiveToRelationships archive =
- concatMap (filePathToRelationships archive) $ filesInArchive archive
+ let mDocXmlPath = getDocumentPath archive
+ in
+ concatMap (filePathToRelationships archive mDocXmlPath) $ filesInArchive archive
filePathIsMedia :: FilePath -> Bool
filePathIsMedia fp =