Skip to content

Commit

Permalink
Docx reader: handle absolute URIs in Relationship Target.
Browse files Browse the repository at this point in the history
Closes #7374.
  • Loading branch information
jgm committed Jun 12, 2021
1 parent ea53a1d commit cfa26e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Text/Pandoc/Readers/Docx/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,26 @@ filePathToRelType path docXmlPath =
then Just InDocument
else Nothing

relElemToRelationship :: DocumentLocation -> Element -> Maybe Relationship
relElemToRelationship relType element | qName (elName element) == "Relationship" =
relElemToRelationship :: FilePath -> DocumentLocation -> Element
-> Maybe Relationship
relElemToRelationship fp relType element | qName (elName element) == "Relationship" =
do
relId <- findAttr (QName "Id" Nothing Nothing) element
target <- findAttr (QName "Target" Nothing Nothing) element
return $ Relationship relType relId target
relElemToRelationship _ _ = Nothing
-- target may be relative (media/image1.jpeg) or absolute
-- (/word/media/image1.jpeg); we need to relativize it (see #7374)
let frontOfFp = T.pack $ takeWhile (/= '_') fp
let target' = fromMaybe target $
T.stripPrefix frontOfFp $ T.dropWhile (== '/') target
return $ Relationship relType relId target'
relElemToRelationship _ _ _ = Nothing

filePathToRelationships :: Archive -> FilePath -> FilePath -> [Relationship]
filePathToRelationships ar docXmlPath fp
| Just relType <- filePathToRelType fp docXmlPath
, Just entry <- findEntryByPath fp ar
, Just relElems <- parseXMLFromEntry entry =
mapMaybe (relElemToRelationship relType) $ elChildren relElems
mapMaybe (relElemToRelationship fp relType) $ elChildren relElems
filePathToRelationships _ _ _ = []

archiveToRelationships :: Archive -> FilePath -> [Relationship]
Expand Down

0 comments on commit cfa26e3

Please sign in to comment.