diff --git a/skills/docx/SKILL.md b/skills/docx/SKILL.md index fb954a46..3e34cac8 100644 --- a/skills/docx/SKILL.md +++ b/skills/docx/SKILL.md @@ -58,6 +58,15 @@ python scripts/office/validate.py out.docx --original doc.docx # XSD checks; - # redlining? add --author "" to check every edit is tracked ``` +When editing OOXML with `xml.dom.minidom` or `defusedxml.minidom`, preserve the existing XML formatting. Serialize with `toxml()`, not `toprettyxml()`: + +```python +with open(xml_path, "wb") as f: + f.write(doc.toxml(encoding="utf-8")) +``` + +`toprettyxml()` inserts indentation and newline text into the package XML and can make the resulting document unreadable in Word or LibreOffice. Do not pretty-print OOXML after editing it. + Word splits text across many `` runs (revision ids, spell-check markers), so a phrase you can see in the document often doesn't exist as a contiguous string in the XML. `merge_runs.py` merges adjacent identically-formatted runs in `word/document.xml` without changing content or rendering; it also accepts a `.docx` directly (`python scripts/merge_runs.py doc.docx -o merged.docx`). **Tracked changes:** when redlining, validate with `--author ""` (needs `--original`) — it reports any text you changed without a ``/`` around it, which is easy to do by accident and invisible in the accepted view. Wrap runs in ``/`` with `w:id`, `w:author`, `w:date` attributes. Inside ``, the text element is ``, not ``. A deleted paragraph mark (``) means "merge this paragraph into the next" — so deleting a paragraph outright is that plus a `` around every run. The `` must come before the rPr's other children; their order is schema-enforced.