fix(docx): read the comments part and render comments as notes (#191)
RA
4d ago+58+58+01234567890123456789-0-0-0123456789
Summary
Word's review layer — word/comments.xml, its relationship, and the w:commentRangeStart / w:commentRangeEnd / w:commentReference anchors — is read and rendered as notes instead of being dropped without a trace. Fixes #191.
What changed
src/package/relationships.rs: arel_type::COMMENTSconstant, so the comments relationship is locatable the same wayFOOTNOTESandENDNOTESare.src/formats/docx/mod.rs: the comments part loads through the existing table-driven note loader, as(comments_part, "comments", "comment", "c", NoteKind::Comment);typed_part_path'scomments.xmlfallback covers producers that omit the relationship. The comment's paragraphs parse with the part's own relationships, exactly like a footnote's.src/formats/docx/content.rs: a"commentReference"arm inwalk_run_contentpushes the note referencec<id>where the comment is anchored;commentRangeStart/Endstay ignored as range boundaries (they carry no content, and the commented text between them renders as normal runs).src/model/mod.rs:NoteKind::Commentdescribes the new source.- Regression test
comments_load_as_notes_and_render: a docx with a comment range around one word plusword/comments.xmlparses into aNoteRef("c1")inline and aNoteKind::Commentnote, and the Markdown keeps the anchored text and renders[^1]: This section needs a citation.
The renderer is already note-kind-agnostic: a comment renders as a Markdown footnote definition in first-reference order, which is how a comment layer survives in Markdown.
Verification
No cargo toolchain was available where I prepared this, so no cargo run is claimed. What I did verify:
- Static trace on HEAD
e7178e0:grep '"sym"\|"commentReference"' src/finds nothing;rel_typehas no comments entry; the note loader indocx/mod.rsiterates only footnotes and endnotes;Inline::NoteRefand the note renderer (render/markdown/mod.rs: numbering by first reference,[^n]:definitions) handle anyNoteKindwithout consulting it. - Every added code path mirrors an existing one line for line:
FOOTNOTES→COMMENTS, the loader table row, and thecommentReferencearm besidefootnoteReference/endnoteReferencein the same match. - The test's fixture follows the module's existing
docx_partshelper and namespace constants; its assertions were walked by hand against the loader's logic (idc1, prefixc, one comment, first-reference number 1).