Scan bookmarks in headers and footers (original idea by @bramj in #22)#176
Merged
Conversation
Document#bookmarks previously only scanned the document body, so bookmarks placed in headers/footers were invisible and couldn't be edited. This extends the scan to headers and footers (keyed by name, like the body). Combined with header/footer write-back (#175), the existing Bookmark insertion API now works for headers and footers and persists on save. Based on the original header-bookmark idea by @bramj in #22 (extended here to cover footers as well). Co-authored-by: bramj <bramj@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced May 31, 2026
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.
Summary
Extends
Document#bookmarksto also scan headers and footers. Until now bookmarks were only collected from the document body (document.xml), so any bookmark placed in a header or footer was invisible to the API and could not be edited.Why this works
The existing
Bookmarkinsertion API (insert_text_before/insert_text_after/insert_multiple_lines) is not body-specific — it operates on the bookmark's own Nokogiri node and creates new nodes in that node's document (element.node.document). Since #173 / #174 expose headers/footers as Nokogiri documents and #175 writes them back on save, scanning their bookmarks is enough to make header/footer bookmark editing fully round-trip. Verified end to end with a save/reopen test.Changes
bookmarksnow appendsw:bookmarkStartnodes found inheaders.valuesandfooters.values(keyed by name, same as the body)._GoBackfiltering and name-keyed Hash semantics are unchanged.spec/fixtures/multi_doc_bookmarks.docx(aheader_bookmarkin the header and afooter_bookmarkin the footer).Note on behavior change
bookmarksnow returns header/footer bookmarks in addition to body ones. Word bookmark names are document-unique, so collisions are unlikely; if a name does collide, last-write-wins in the order body → headers → footers. This is effectively a completeness fix.Credit
Based on the original header-bookmark idea by @bramj in #22, extended here to also cover footers. They are credited as a co-author on the commit and should be credited in the release notes when this ships.
Tests
145 examples, 0 failures).Closes #22
🤖 Generated with Claude Code