Skip to content

Add endnote support (word/endnotes.xml) #94

Closed

Description

@toxicphreAK

Document.footnotes, Footnotes.add_footnote() and Run.add_footnote_reference() landed in #34, but the endnote half of the same feature did not. A document's endnotes are unreachable: word/endnotes.xml is never loaded, there is no EndnotesPart, and w:endnoteReference in a run is invisible to the API.

The two are near-identical in the schema — both w:footnote and w:endnote are CT_FtnEdn, both parts are CT_Footnotes/CT_Endnotes wrapping a sequence of those, and w:footnoteReference and w:endnoteReference are both CT_FtnEdnRef. ST_FtnEdn (normal, separator, continuationSeparator) is already in oxml/simpletypes.py and its docstring already says it covers w:endnote/@w:type. CT.WML_ENDNOTES and RT.ENDNOTES are already in opc/constants.py.

So this is mostly a matter of generalising what parts/footnotes.py, oxml/footnotes.py and footnotes.py already do rather than writing a new feature from scratch.

Where the prior art is

br-rkdrnf/python-docx, branches footnotes and bering, has a combined implementation under docx/fntent/ (fntent.py, footnoteReference.py, endnoteReference.py) with docx/oxml/fntent.py and docx/parts/fntent.py, plus default-endnotes.xml and default-footnotes.xml templates. It handles footnotes and endnotes through one code path. It is written against upstream v0.8.7 and predates our footnote work, so it is a design reference rather than something to port.

Shape

  • EndnotesPart in parts/endnotes.py, alongside FootnotesPart
  • CT_Endnotes / reuse of CT_FtnEdn in oxml/footnotes.py
  • Document.endnotes -> Endnotes, mirroring Document.footnotes
  • Endnotes.add_endnote(), Endnote.text, Endnote.endnote_id
  • Run.add_endnote_reference()
  • Creating the part on demand when the document has none, the way FootnotesPart does
  • Endnote position and numbering live in w:sectPr/w:endnotePr and w:settings/w:endnotePr, both of which are already in the _tag_seq lists — exposing them is optional follow-up, not part of this

Note that Document.iter_inner_content()'s docstring already mentions endnotes; check what it does today and make it consistent.

Activity

  1. toxicphreAK commented on Aug 5, 2026

    @toxicphreAK
    OwnerAuthor

    Landed in #139. Generalised rather than duplicated: _CT_FtnEdnCollection and _Notes hold the shared behaviour and the two spellings differ only in tag names and styles. Document.replace_text(footnotes=True) now reaches endnotes, which its docstring already claimed. Endnote position in w:endnotePr remains follow-up, as the issue said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions