Skip to content

fix(docx): read footnote/endnote body text from the separate OPC parts - #4374

Merged
dolfim-ibm merged 1 commit into
docling-project:mainfrom
avanish-garg:fix/docx-footnote-endnote-content-dropped
Sep 28, 2026
Merged

dolfim-ibm merged 1 commit into
docling-project:mainfrom
avanish-garg:fix/docx-footnote-endnote-content-dropped

Conversation

@avanish-garg

Copy link
Copy Markdown

Issue resolved by this Pull Request:
Resolves #4372

Extends MsWordDocumentBackend to read the word/footnotes.xml/word/endnotes.xml OPC parts
directly (via docx_obj.part.rels, filtering by RELATIONSHIP_TYPE.FOOTNOTES/ENDNOTES, then
docx.oxml.parse_xml on the raw part bytes — python-docx has no high-level model for these
parts, unlike headers/footers). Each note's body 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.

Changes: docling/backend/msword_backend.py gets a new _add_footnotes_and_endnotes method,
called once after the main body walk (same place _add_header_footer/_add_comments are
called). tests/test_backend_msword.py gets a new regression test building a minimal DOCX with a
real 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 main with the
exact symptom described (footnote items list is empty), and pass with the fix.

Full tests/test_backend_msword.py + tests/test_backend_msword_lists.py suite: 70 tests pass,
no regressions. ruff check/ruff format: clean. ty check: diffed against unmodified main —
same 12 pre-existing warnings (unrelated lines), no new ones. Does not touch any existing
reference/groundtruth test data.

Checklist:

  • Documentation has been updated, if necessary. — n/a, no user-facing docs describe footnote
    handling to update
  • Examples have been added, if necessary. — n/a
  • Tests have been added, if necessary.

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]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @avanish-garg, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/msword_backend.py 75.00% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@ceberam ceberam added bug Something isn't working docx issue related to docx backend labels Sep 25, 2026
@dolfim-ibm
dolfim-ibm merged commit 6167240 into docling-project:main Sep 28, 2026
67 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working docx issue related to docx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX backend silently drops footnote/endnote body text

4 participants