diff options
| author | John MacFarlane <[email protected]> | 2025-04-08 12:55:27 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-04-08 12:55:27 -0700 |
| commit | d1f197c86b6165a2202900344fc5a865247804c3 (patch) | |
| tree | 85cf14e281be73625c357b34134e562dc1d7266d | |
| parent | 26188693973c0f48e8f7ade8841058266174b066 (diff) | |
Docx writer: don't renumber rels.issue10769
This fixes a regression introduced by af57648.
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.
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 32 |
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")] () ] |
