Repository navigation
fix(docx): read footnote/endnote body text from the separate OPC parts - #4374
Merged
dolfim-ibm merged 1 commit intoSep 28, 2026
Conversation
MsWordDocumentBackend only ever walked the document body (docx_obj.element.body), so a paragraph's w:footnoteReference/ w:endnoteReference never resolved to anything: python-docx's Run.text only concatenates w:t nodes, and the actual body text lives in a separate word/footnotes.xml/endnotes.xml part that python-docx has no high-level model for and nothing in this backend ever opened. The content was silently dropped with no warning, even for a common, valid DOCX (footnotes are ubiquitous in academic/legal/business documents). Each note's body now becomes its own FOOTNOTE item in the furniture layer, the same layer headers/footers already use in this backend and the same convention the iWork backend uses for its own footnotes: available to callers, out of the reading order by default. Word's own separator/continuationSeparator placeholders (present in every Word-authored document, holding no user content) are skipped. Tests: new regression test building a minimal DOCX with a real footnote and endnote (plus the separator placeholders every real document carries), confirming both are recovered and placeholders are not. Verified the test fails on unmodified main and passes with the fix. Full existing tests/test_backend_msword.py + tests/test_backend_msword_lists.py suite (70 tests) still passes; ruff/ty clean against the pre-existing baseline (diffed to confirm no new warnings). Signed-off-by: Avanish Garg <[email protected]>
Contributor
|
✅ DCO Check Passed Thanks @avanish-garg, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
dolfim-ibm
approved these changes
Sep 28, 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.
Issue resolved by this Pull Request:
Resolves #4372
Extends
MsWordDocumentBackendto read theword/footnotes.xml/word/endnotes.xmlOPC partsdirectly (via
docx_obj.part.rels, filtering byRELATIONSHIP_TYPE.FOOTNOTES/ENDNOTES, thendocx.oxml.parse_xmlon the raw part bytes —python-docxhas no high-level model for theseparts, unlike headers/footers). Each note's body becomes its own
FOOTNOTEitem in the furniturelayer, the same layer headers/footers already use in this backend and the same convention the
iWork backend uses for its own footnotes: available to callers, out of the reading order by
default. Word's own separator/continuationSeparator placeholders (present in every Word-authored
document, holding no user content) are skipped.
Changes:
docling/backend/msword_backend.pygets a new_add_footnotes_and_endnotesmethod,called once after the main body walk (same place
_add_header_footer/_add_commentsarecalled).
tests/test_backend_msword.pygets a new regression test building a minimal DOCX with areal footnote and endnote plus the separator placeholders every real document carries, confirming
both notes are recovered and placeholders are not — verified to fail on unmodified
mainwith theexact symptom described (footnote items list is empty), and pass with the fix.
Full
tests/test_backend_msword.py+tests/test_backend_msword_lists.pysuite: 70 tests pass,no regressions.
ruff check/ruff format: clean.ty check: diffed against unmodifiedmain—same 12 pre-existing warnings (unrelated lines), no new ones. Does not touch any existing
reference/groundtruth test data.
Checklist:
handling to update