Add ability to read document headers#173
Merged
Merged
Conversation
inspired from #73 but stripped down to just the header to see if that might be more amenable to get in. Also because of the TODO note in the update function, only supports reading these files, not updating them.
satoryu
added a commit
that referenced
this pull request
May 31, 2026
Adds a Docx::Document#footers accessor that exposes word/footer*.xml as a Hash keyed by footer file name, mirroring the headers reading feature (#173). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Jawad Ahmad <Jawad79Ahmad@users.noreply.github.com>
This was referenced May 31, 2026
pull Bot
pushed a commit
to NeatNerdPrime/docx
that referenced
this pull request
May 31, 2026
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 (ruby-docx#173, ruby-docx#174). Based on the original read/write implementation by @aashish in ruby-docx#42. Co-authored-by: aashish <aashish@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
Adds the ability to read document headers (
word/header*.xml) via a newDocx::Document#headersaccessor. Headers are exposed as aHashkeyed by the header file name (e.g."header1"), with each value being a parsedNokogiri::XMLdocument.Background / Credit
This is a rebased version of #137 by @FeminismIsAwesome (Ian Norris). That PR had grown stale and conflicted with
masterafter theSimpleInspectand ZIP64 (#168 / #172) changes. The original commit and authorship are preserved here; only the merge conflicts inlib/docx/document.rbwere resolved. It addresses #32.The implementation follows the existing
load_stylesconvention (a privateload_headersmethod called frominitialize), keeping it consistent with the current codebase.Scope
Intentionally minimal — header reading only. Footers and write-back are out of scope and left for a follow-up (this mirrors the deliberate scope of #137, and avoids the riskier round-trip/file-name-mapping concerns raised against the alternative #153).
Known limitations
headersexposes mutableNokogiridocuments, butupdate(onsave/stream) does not write headers back. Editing a header and saving will not persist the change (read-only).word/footer*.xml) are not handled.Tests
spec/fixtures/multi_doc.docxand aread headersspec.139 examples, 0 failures).Closes #137
🤖 Generated with Claude Code