aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-04-08 15:00:16 -0700
committerGitHub <[email protected]>2025-04-08 15:00:16 -0700
commitc1cb32b3ab425dd5dde2a4fc1144a50fd08f1ab8 (patch)
treea0c1a7148f7e31f50a65f7b0e23d2c35ab07792d /src
parent961b5642a29faa4dfd0a061562ad78f9be447884 (diff)
Docx writer: don't renumber rels. (#10770)
This fixes a regression introduced by af57648. We used to renumber the Relationships so they didn't conflict with the set of fixed Relationships we imposed. We are now preserving the ids from the reference doc's document.xml.refs, so we shouldn't renumber them or references introduced by the user (e.g. in a template) will fail. Closes #10769.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 596bb6944..a1c25cae6 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -62,29 +62,6 @@ import Text.Pandoc.XML.Light as XML
import Data.Generics (mkT, everywhere)
import Text.Collate.Lang (renderLang, Lang(..))
-renumIdMap :: Int -> [Element] -> M.Map Text Text
-renumIdMap _ [] = M.empty
-renumIdMap n (e:es)
- | Just oldId <- findAttr (QName "Id" Nothing Nothing) e =
- M.insert oldId ("rId" <> tshow n) (renumIdMap (n+1) es)
- | otherwise = renumIdMap n es
-
-replaceAttr :: (QName -> Bool) -> Text -> [XML.Attr] -> [XML.Attr]
-replaceAttr f val = map $
- \a -> if f (attrKey a) then XML.Attr (attrKey a) val else a
-
-renumId :: (QName -> Bool) -> M.Map Text Text -> Element -> Element
-renumId f renumMap e
- | Just oldId <- findAttrBy f e
- , Just newId <- M.lookup oldId renumMap =
- let attrs' = replaceAttr f newId (elAttribs e)
- in
- e { elAttribs = attrs' }
- | otherwise = e
-
-renumIds :: (QName -> Bool) -> M.Map Text Text -> [Element] -> [Element]
-renumIds f renumMap = map (renumId f renumMap)
-
writeDocx :: (PandocMonad m)
=> WriterOptions -- ^ Writer options
-> Pandoc -- ^ Document to convert
@@ -237,15 +214,10 @@ writeDocx opts doc = do
, stCurId = newMaxRelId + 1
}
- let idMap = renumIdMap (length baserels + 1) (headers ++ footers)
-
-- adjust contents to add sectPr from reference.docx
let sectpr = case mbsectpr of
- Just sectpr' -> let cs = renumIds
- (\q -> qName q == "id" && qPrefix q == Just "r")
- idMap
- (elChildren sectpr')
- in add_attrs (elAttribs sectpr') $ mknode "w:sectPr" [] cs
+ Just sectpr' -> add_attrs (elAttribs sectpr') $ mknode "w:sectPr" []
+ (elChildren sectpr')
Nothing -> mknode "w:sectPr" []
[ mknode "w:footnotePr" []
[ mknode "w:numRestart" [("w:val","eachSect")] () ]