Repository navigation
fix(docx): name a page reference's field after its anchor's own bookmark - #907
Merged
Merged
Conversation
A page reference minted its anchor's bookmark name when it was written, ahead of the anchor's own bookmark, and an anchor that cleans to the name of another took it: a reference to "a." gave "a." the name "a", pushed the anchor "a" to "a_2", which the anchor "a_2" is given too, and the file held two bookmarks of one name. The field is now written without the name and settled once the body is: named after the bookmark its anchor was written under, or taken back to the number it reads where the anchor has none. A reference names no bookmark of its own. Tests cover a reference to a layer stack's column, the run style the number keeps, a reference to an anchor in a later section and a face set only in a later section's zone.
DemchaAV
added a commit
that referenced
this pull request
Oct 15, 2026
…ne (#908) The Linux baseline held the five documents #899 moves (cv-orange_ops, cv-serif_headline, invoice-workspace, proposal-editorial, proposal-northline) as they stood before it, while every CI run since measures them as #899's did. Both files now match the docx-fidelity artifact of #907's run (38794754386) byte for byte: 45 lines nearer the page, 2 further by 0.05pt, all others unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Since #906, every page reference is written as a
PAGEREFfield and checked once the body is written. The field was named when the reference was written, throughDocxBookmarkNames.nameFor(anchor), so the reference minted its anchor's bookmark name before the anchor's own bookmark did.Two anchors can clean to the same name, so that order matters. Take a reference to
a., an anchor that exists nowhere, followed by paragraphs anchoredaanda_2:a.took the namea;awas pushed toa_2;a_2was givena_2too.The file held two bookmarks named
a_2, so links and fields to either landed wherever Word keeps that name. Before #906, a reference whose anchor got no bookmark minted no name.What changed
writePageReferencewrites the field with no bookmark name and records its instruction (appendFieldnow returns it) together with the reference's anchor. The reference names no bookmark of its own.settleThePageReferencesreplacesunfieldTheReferencesWithoutABookmark. Once every section is written, it names each field after the bookmark its anchor was written under, whichopenAnchorandbookmarkAroundrecord by anchor. A reference whose anchor got no bookmark is taken back to the number it reads, with its note, as before.PageReferenceNoderejects blank anchors.Verification
DocxPageReferenceTest:a.comes before the anchorsaanda_2, and the file holds exactlyaanda_2, with no field;DocxMultiSectionTest:PAGEREFfield;2.5-devbefore fix(docx): read a table's cells, headers and list runs; check page references #906:./mvnw -B -ntp clean verify→ BUILD SUCCESS (render-docx 1628, qa 1820).Lane: shared-engine (render-docx semantic DOCX backend), no public API change. Follow-up to #906.