docx writer: avoid extra copy of abstractNum and num elements...
...in numbering.xml. This caused pandoc-produced docx files to
be uneditable using Word Online.
The problem was that recent versions of reference.docx include
samples of various kinds of text, including lists. The
numering elements for these were getting copied over to
the new docx, where they clashed with the autogenerated
elements produced by pandoc. This didn't confuse Desktop
Word, but it did confuse Word Online.
Closes #5358.
commitb7cbd7b8c91915db5b4146af53f24e82d9394e1f
authorJohn MacFarlane <jgm@berkeley.edu>
dateMon 11 Mar 2019, 22:09 (8 years ago)
parentf7ebd51
src/Text/Pandoc/Writers/Docx.hs+9−1
@@ -465,7 +465,15 @@ writeDocx opts doc@(Pandoc meta _) = do
465465 let numpath = "word/numbering.xml"
466466 numbering <- parseXml refArchive distArchive numpath
467467 newNumElts <- mkNumbering (stLists st)
468− let allElts = onlyElems (elContent numbering) ++ newNumElts
468+ let pandocAdded e =
469+ case findAttrBy ((== "abstractNumId") . qName) e >>= safeRead of
470+ Just numid -> numid >= (990 :: Int)
471+ Nothing ->
472+ case findAttrBy ((== "numId") . qName) e >>= safeRead of
473+ Just numid -> numid >= (1000 :: Int)
474+ Nothing -> False
475+ let oldElts = filter (not . pandocAdded) $ onlyElems (elContent numbering)
476+ let allElts = oldElts ++ newNumElts
469477 let numEntry = toEntry numpath epochtime $ renderXml numbering{ elContent =
470478 -- we want all the abstractNums first, then the nums,
471479 -- otherwise things break:
test/docx/golden/block_quotes.docx
Binary file not shown.
test/docx/golden/codeblock.docx
Binary file not shown.
test/docx/golden/comments.docx
Binary file not shown.
test/docx/golden/custom_style_no_reference.docx
Binary file not shown.
test/docx/golden/definition_list.docx
Binary file not shown.
test/docx/golden/document-properties-short-desc.docx
Binary file not shown.
test/docx/golden/document-properties.docx
Binary file not shown.
test/docx/golden/headers.docx
Binary file not shown.
test/docx/golden/image.docx
Binary file not shown.
test/docx/golden/inline_code.docx
Binary file not shown.
test/docx/golden/inline_formatting.docx
Binary file not shown.
test/docx/golden/inline_images.docx
Binary file not shown.
test/docx/golden/link_in_notes.docx
Binary file not shown.
test/docx/golden/links.docx
Binary file not shown.
test/docx/golden/lists.docx
Binary file not shown.
test/docx/golden/lists_continuing.docx
Binary file not shown.
test/docx/golden/lists_restarting.docx
Binary file not shown.
test/docx/golden/nested_anchors_in_header.docx
Binary file not shown.
test/docx/golden/notes.docx
Binary file not shown.
test/docx/golden/table_one_row.docx
Binary file not shown.
test/docx/golden/table_with_list_cell.docx
Binary file not shown.
test/docx/golden/tables.docx
Binary file not shown.
test/docx/golden/track_changes_deletion.docx
Binary file not shown.
test/docx/golden/track_changes_insertion.docx
Binary file not shown.
test/docx/golden/track_changes_move.docx
Binary file not shown.
test/docx/golden/unicode.docx
Binary file not shown.
test/docx/golden/verbatim_subsuper.docx
Binary file not shown.