Persist header and footer edits on save (original work by @aashish in #42)#175
Merged
Conversation
Extends Document#update to write modified headers and footers back into the archive on save/stream, keyed by their original file name (so multiple and non-sequential header/footer files round-trip correctly). Builds on the header/footer reading support (#173, #174). Based on the original read/write implementation by @aashish in #42. Co-authored-by: aashish <aashish@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced May 31, 2026
pull Bot
pushed a commit
to NeatNerdPrime/docx
that referenced
this pull request
May 31, 2026
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 (ruby-docx#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 ruby-docx#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 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
Makes header and footer edits persist on
save/stream. Until nowDocument#headersand#footers(added in #173 / #174) were read-only — editing the returnedNokogiridocuments had no effect becauseupdateonly wrote backdocument.xmlandstyles.xml. This extendsupdateto write each header/footer back into the archive.Approach
Each header/footer is written back keyed by its original file name (the
headers/footersHash key, e.g."header1"):Using the stored file name (rather than reconstructing
header#{index+1}.xml) means documents with multiple or non-sequential header/footer files round-trip correctly without risk of overwriting the wrong entry.Credit
Based on the original read/write implementation by @aashish in #42. They are credited as a co-author on the commit and should be credited in the release notes when this ships.
Tests
multi_doc.docx, edit the header and footer text, save, reopen, and assert the changes persisted.141 examples, 0 failures).Closes #42
🤖 Generated with Claude Code