fix(docx): make a block's anchor a bookmark Word can link to - #728
Merged
Merged
Conversation
Only a paragraph's anchor(...) reached the file as a bookmark; an anchor on a section, container, table or image was dropped, so an internal link to one went nowhere in Word. Such a block's anchor now wraps everything it wrote, opening before the first word of its first paragraph (its first cell's, when it starts with a table) and closing after its last.
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
anchor(...)sits on a paragraph, a section, a container, a table or an image, andlinkTo(...)jumps to it. The DOCX export wrote a Word bookmark only for a paragraph's anchor. An anchor on any other block was dropped. The link to it was still written, withw:anchornaming a bookmark that did not exist, so in Word it went nowhere.This is also the precondition for page references. A
PAGEREFfield to a block's anchor has to find a bookmark, or Word shows "Error! Bookmark not defined." when the field updates.What changed
DocxSemanticBackend.writeNodenow wraps a block's output in a bookmark named after its anchor (bookmarkAround). This covers a section, a container, a table and an image. It goes through the sameDocxBookmarkNamesas paragraph anchors, so the name a link uses is the name the bookmark carries. It sits alongside the existing keep-together pass.addNewBookmarkStartappends after the runs, so the element is moved with anXmlCursorto just after the paragraph'sw:pPr.Verification
In an editor. A document with a link on page 1 to a section anchor on page 2, converted with LibreOffice: the link's destination is page 2, where the section starts.
Gate. Full reactor gate (
clean verifyover core, render-pdf/docx/pptx, templates, testing, qa, coverage) → BUILD SUCCESS. Examples after install: 93 green. No committed preview moved.New
DocxBlockAnchorTest(4):w:anchornames it;Removing the move to the paragraph start fails the section test.
Lane: shared-engine (render-docx). No public API change.