Skip to content

fix: preserve unknown empty elements inside runs (w:commentReference)#5

Open
dryheatwindbag wants to merge 1 commit into
tensorbee:mainfrom
HelloJoyceAI:fix/preserve-empty-run-elements
Open

fix: preserve unknown empty elements inside runs (w:commentReference)#5
dryheatwindbag wants to merge 1 commit into
tensorbee:mainfrom
HelloJoyceAI:fix/preserve-empty-run-elements

Conversation

@dryheatwindbag

Copy link
Copy Markdown

Bug

CT_R::from_xml's Event::Empty branch handles tab, br, footnoteReference, and endnoteReference — and silently drops every other empty element inside <w:r>.

The most visible casualty is w:commentReference: on any read→write round-trip of a document containing Word comments, the word/comments.xml part and its relationship survive, but the body anchors are destroyed — every comment is orphaned. Any other empty run-level markup (current or future OOXML, vendor extensions) is likewise lost.

Fix

One else arm, mirroring the unknown-element fallback the function already has for Event::Start (and that CT_P::from_xml has for both event kinds):

} else {
    extra_xml.push(capture_empty_element(e)?);
}

Test

Adds unknown_empty_run_children_roundtrip: a paragraph whose run contains <w:commentReference w:id="1"/> round-trips verbatim. Fails on main, passes with the fix.

cargo test -p rdocx-oxml: 106 passed, 0 failed. cargo fmt --check clean.

Found while round-trip testing documents that carry reviewer comments — happy to adjust anything about the approach.

CT_R::from_xml's Event::Empty branch handled tab/br/footnoteReference/
endnoteReference and silently dropped every other empty element inside
<w:r>. This destroys w:commentReference anchors on round-trip (the
comments part survives but every comment is orphaned), and loses any
other empty run-level markup.

Add the same unknown-element fallback the function already has for
Event::Start (and CT_P has for both): capture the element into
extra_xml via capture_empty_element.

Includes a regression test: a run containing <w:commentReference/>
round-trips verbatim.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant