From d4dd5e9ab945fca7b3e6bcc97993381a12eb39ab Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 15 Oct 2025 23:23:45 +0200 Subject: Docx writer: properly handle nested comment spans. Patch credit: @mmourino. Closes #8189. Closes #6959. --- src/Text/Pandoc/Writers/Docx/OpenXML.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/Docx/OpenXML.hs b/src/Text/Pandoc/Writers/Docx/OpenXML.hs index c9c1bc80f..f687a3493 100644 --- a/src/Text/Pandoc/Writers/Docx/OpenXML.hs +++ b/src/Text/Pandoc/Writers/Docx/OpenXML.hs @@ -773,17 +773,20 @@ inlineToOpenXML' _ (Span (ident,["comment-start"],kvs) ils) = do kvs' = filter (("id" /=) . fst) kvs modify $ \st -> st{ stComments = (("id",ident'):kvs', ils) : stComments st } return [ Elem $ mknode "w:commentRangeStart" [("w:id", ident')] () ] -inlineToOpenXML' _ (Span (ident,["comment-end"],kvs) _) = +inlineToOpenXML' opts (Span (ident,["comment-end"],kvs) content) = do -- prefer the "id" in kvs, since that is the one produced by the docx -- reader. let ident' = fromMaybe ident (lookup "id" kvs) - in return . map Elem $ - [ mknode "w:commentRangeEnd" [("w:id", ident')] () - , mknode "w:r" [] - [ mknode "w:rPr" [] - [ mknode "w:rStyle" [("w:val", "CommentReference")] () ] - , mknode "w:commentReference" [("w:id", ident')] () ] - ] + -- process nested content: see #8189 + nestedContent <- inlinesToOpenXML opts content + let thisCommentEnd = + [ mknode "w:commentRangeEnd" [("w:id", ident')] () + , mknode "w:r" [] + [ mknode "w:rPr" [] + [ mknode "w:rStyle" [("w:val", "CommentReference")] () ] + , mknode "w:commentReference" [("w:id", ident')] () ] + ] + return $ map Elem thisCommentEnd ++ nestedContent inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do stylemod <- case lookup dynamicStyleKey kvs of Just (fromString . T.unpack -> sty) -> do -- cgit v1.2.3