summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorEdwin Török <edwin@etorok.net>2023-12-24 23:37:59 +0000
committerJohn MacFarlane <jgm@berkeley.edu>2023-12-26 22:51:28 -0800
commit075cbb6419d542022ac62e0a0c075685b41a9276 (patch)
tree57845b626022bb1e00526305f9d910b0b9190314 /src/Text
parent0ba8af939c7bf95882ea8c2e877f20fd533202fc (diff)
fix(docx): support absolute header/footer paths
Header and footer references may be absolute in the reference.docx. E.g. editing it with dotnet's Open-XML-SDK causes this error: ``` + pandoc test.md -t docx --reference-doc referenceh.docx -o test.docx word//word/header1.xml missing in reference docx ``` There was already code in pandoc to handle relative vs absolute paths in references, so use it. Signed-off-by: Edwin Török <edwin@etorok.net>
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs5
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 4dc9543cf..57f6e4c1c 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -56,6 +56,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
, constructBogusParStyleData
, leftBiasedMergeRunStyle
, rowsToRowspans
+ , extractTarget
) where
import Text.Pandoc.Readers.Docx.Parse.Styles
import Codec.Archive.Zip
@@ -538,6 +539,10 @@ relElemToRelationship fp relType element | qName (elName element) == "Relationsh
return $ Relationship relType relId target'
relElemToRelationship _ _ _ = Nothing
+extractTarget :: Element -> Maybe Target
+extractTarget element = do (Relationship _ _ target) <- relElemToRelationship "word/" InDocument element
+ return target
+
filePathToRelationships :: Archive -> FilePath -> FilePath -> [Relationship]
filePathToRelationships ar docXmlPath fp
| Just relType <- filePathToRelType fp docXmlPath
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index afafd6926..07633922f 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -64,6 +64,7 @@ import Text.Pandoc.ImageSize
import Text.Pandoc.Logging
import Text.Pandoc.MIME (extensionFromMimeType, getMimeType, getMimeTypeDef)
import Text.Pandoc.Options
+import Text.Pandoc.Readers.Docx.Parse (extractTarget)
import Text.Pandoc.Writers.Docx.StyleMap
import Text.Pandoc.Writers.Docx.Table as Table
import Text.Pandoc.Writers.Docx.Types
@@ -310,8 +311,6 @@ writeDocx opts doc = do
let headers = filterElements isHeaderNode parsedRels
let footers = filterElements isFooterNode parsedRels
- let extractTarget = findAttr (QName "Target" Nothing Nothing)
-
-- we create [Content_Types].xml and word/_rels/document.xml.rels
-- from scratch rather than reading from reference.docx,
-- because Word sometimes changes these files when a reference.docx is modified,