Skip to content

docx_plus.notes.read

Read footnotes and endnotes from a document. Each result is paired with the paragraph index of its reference marker so callers can locate where the note is referenced. Reserved entries (separator and continuation separator, ids -1 and 0) are filtered out before results are returned.

docx_plus.notes.read

Read footnotes / endnotes from a document.

Each note is paired with the paragraph index of its reference marker in the body so callers can locate where the note is referenced.

This module imports only from docx_plus.core (SPEC §9.1).

NoteContent dataclass

NoteContent(note_id: int, text: str, paragraph_index: int)

A footnote or endnote with its body text and reference location.

Attributes:

Name Type Description
note_id int

The w:id value of the note.

text str

The note body text. Reserved separator entries (ids -1 and 0) are filtered out before this list is built, so callers see only user-authored notes.

paragraph_index int

Zero-based index (within doc.paragraphs) of the paragraph holding the reference marker. -1 if the note is in the part but no body reference exists.

read_footnotes

read_footnotes(doc: Document) -> list[NoteContent]

Return every user-authored footnote in doc.

Reserved entries (separator and continuation separator, ids -1 and 0) are filtered out.

Parameters:

Name Type Description Default
doc Document

The python-docx :class:~docx.document.Document to scan.

required

Returns:

Name Type Description
One list[NoteContent]

class:NoteContent per footnote, in part order. [] if

list[NoteContent]

the document has no footnotes part.

Source code in docx_plus/notes/read.py
def read_footnotes(doc: Document) -> list[NoteContent]:
    """Return every user-authored footnote in ``doc``.

    Reserved entries (separator and continuation separator, ids ``-1``
    and ``0``) are filtered out.

    Args:
        doc: The python-docx :class:`~docx.document.Document` to scan.

    Returns:
        One :class:`NoteContent` per footnote, in part order. ``[]`` if
        the document has no footnotes part.
    """
    return _read_notes(
        doc,
        relationship_type=RT.FOOTNOTES,
        note_tag="./w:footnote",
        ref_tag=".//w:footnoteReference",
    )

read_endnotes

read_endnotes(doc: Document) -> list[NoteContent]

Return every user-authored endnote in doc.

Same contract as :func:read_footnotes.

Source code in docx_plus/notes/read.py
def read_endnotes(doc: Document) -> list[NoteContent]:
    """Return every user-authored endnote in ``doc``.

    Same contract as :func:`read_footnotes`.
    """
    return _read_notes(
        doc,
        relationship_type=RT.ENDNOTES,
        note_tag="./w:endnote",
        ref_tag=".//w:endnoteReference",
    )