From 2c464c8b11410902faa8902fa03e5441c5daa27e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 6 Nov 2026 08:52:59 -0800 Subject: [PATCH] Docx reader: don't drop contents of customXml element. Closes #12050. --- src/Text/Pandoc/Readers/Docx/Parse.hs | 5 +++- test/Tests/Readers/Docx.hs | 4 +++ test/docx/custom_xml.docx | Bin 0 -> 995 bytes test/docx/custom_xml.native | 36 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/docx/custom_xml.docx create mode 100644 test/docx/custom_xml.native diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index 367cb74cc..527438fac 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -1219,7 +1219,7 @@ elemToParPart' ns element (matchQName "drawingml" "chart" (Just "c") "chart") drawingElem = return [Chart] elemToParPart' ns element - | isElem ns "w" "r" element = do + | isElem ns "w" "r" element || isElem ns "w" "customXml" element = do runs <- elemToRun ns element return $ map PlainRun runs elemToParPart' ns element @@ -1364,6 +1364,9 @@ elemToRun ns element runElems <- elemToRunElems ns element runStyle <- elemToRunStyleD ns element return [Run runStyle runElems] +elemToRun ns element + | isElem ns "w" "customXml" element = + mconcat <$> mapM (elemToRun ns) (elChildren element) elemToRun _ _ = throwError WrongElem getParentStyleValue :: (ParStyle -> Maybe a) -> ParStyle -> Maybe a diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs index a03eb1589..bc3408842 100644 --- a/test/Tests/Readers/Docx.hs +++ b/test/Tests/Readers/Docx.hs @@ -219,6 +219,10 @@ tests = [ testGroup "document" "nested Smart Tags" "docx/nested_smart_tags.docx" "docx/nested_smart_tags.native" + , testCompare + "inline customXml elements" + "docx/custom_xml.docx" + "docx/custom_xml.native" , testCompare "remove anchor spans with nothing pointing to them" "docx/unused_anchors.docx" diff --git a/test/docx/custom_xml.docx b/test/docx/custom_xml.docx new file mode 100644 index 0000000000000000000000000000000000000000..31221f59573bec15a577bf3161e46eb2c3de8714 GIT binary patch literal 995 zcmWIWW@Zs#U}E54;BrfgJ?SsC;WYyT!#YL=24Nr_?VO)ilA2c%A5vM6S{$oak(*N+ zu-EUffxx{=uG89GvJwJLo>m`>nVc&dCf9oEyxIJ;*!%Z4i`$~?)#D0_SK?RJP9w;a3e?L)V8dLhZ)=4bX=g#S!Q@$)Poh`|{ zp^I~+Qt}x_FWb*cglG8A2)MuP?Od~oTtS(q9x1lJ<8;6ALup?5*IJ!P7dMOayFZ$A z)!XBwHS^L(Ro>siy^6g8LMtD9cq0@a-gHG=SnSFBhRN^N>P?>O`jKzv9;X#Le?>Q6 zHJjzT!t3k)v#s+AW#%5-TvzCADV4HrGW+^-9t`gGf4?Tadng@%5;i*hE^Yne6ne> zny`>&hd0l%Ifv(6Qc>Tc6l%9Xd-6qh?IO*^%N$R1U+^$5-MjSTU50;&lj00J_GUHk zcps?GvF~$xbnx_Q*Xi|het3yQy7bOGc-P(a>grfgF^&9}$GiV|GFkC*Vjx)%+=YPA&D>d`DyE3=idE!w-IT z+ulz8a*EAx+Qe|9>b=RWah8+!PpOD*=UaVM;oR@jA8l6t3|P`-5ai z8C*M$o$fxhA@ccyt_`Z9%2FE|*E$9i6#x9Ju~x~kLjR@y^X;2zqDte0&GxPdoBHy> z{x2&Y9lX!`