git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Fix ids in comment writing

Comments from `--track-changes=all` were producing corrupt docx, because the writer was trying to get id from the `(ID,_,_)` field of the attributes, and ignoring the "id" entry in the key-value pairs. We now check both. There is a larger conversation to be had about the right way to treat "id" and "class" entries in kvs, but this fix will correctly interpret the output of the docx reader work.

commitae2157fe8bca342ba23881e0f5dfba8d9fb07d84 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSat 27 Jan 2018, 07:21 (9 years ago) parent61f80e7
1 file changed+17−9
src/Text/Pandoc/Writers/Docx.hs+17−9
src/Text/Pandoc/Writers/Docx.hs+17−9
@@ -1104,15 +1104,23 @@ inlineToOpenXML' _ (Str str) =
11041104inlineToOpenXML' opts Space = inlineToOpenXML opts (Str " ")
11051105inlineToOpenXML' opts SoftBreak = inlineToOpenXML opts (Str " ")
11061106inlineToOpenXML' _ (Span (ident,["comment-start"],kvs) ils) = do
1107− modify $ \st -> st{ stComments = (("id",ident):kvs, ils) : stComments st }
1108− return [ mknode "w:commentRangeStart" [("w:id", ident)] () ]
1109−inlineToOpenXML' _ (Span (ident,["comment-end"],_) _) =
1110− return [ mknode "w:commentRangeEnd" [("w:id", ident)] ()
1111− , mknode "w:r" []
1112− [ mknode "w:rPr" []
1113− [ mknode "w:rStyle" [("w:val", "CommentReference")] () ]
1114− , mknode "w:commentReference" [("w:id", ident)] () ]
1115− ]
1107+ -- prefer the "id" in kvs, since that is the one produced by the docx
1108+ -- reader.
1109+ let ident' = fromMaybe ident (lookup "id" kvs)
1110+ kvs' = filter (("id" /=) . fst) kvs
1111+ modify $ \st -> st{ stComments = (("id",ident'):kvs', ils) : stComments st }
1112+ return [ mknode "w:commentRangeStart" [("w:id", ident')] () ]
1113+inlineToOpenXML' _ (Span (ident,["comment-end"],kvs) _) =
1114+ -- prefer the "id" in kvs, since that is the one produced by the docx
1115+ -- reader.
1116+ let ident' = fromMaybe ident (lookup "id" kvs)
1117+ in
1118+ return [ mknode "w:commentRangeEnd" [("w:id", ident')] ()
1119+ , mknode "w:r" []
1120+ [ mknode "w:rPr" []
1121+ [ mknode "w:rStyle" [("w:val", "CommentReference")] () ]
1122+ , mknode "w:commentReference" [("w:id", ident')] () ]
1123+ ]
11161124inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do
11171125 stylemod <- case lookup dynamicStyleKey kvs of
11181126 Just sty -> do