Skip to content

bookmark

bookmark

Custom element classes for bookmarks.

A bookmark is a named range delimited by a w:bookmarkStart and a matching w:bookmarkEnd, paired by their w:id. The pair is not nested in anything: the two elements sit as siblings of whatever content they surround, which is what lets a bookmark span paragraphs, table cells and block containers without regard to the structure in between.

It also means an unmatched start or end is structurally possible, and real documents contain them, so nothing here treats a missing counterpart as an error.

CT_BookmarkStart

Bases: BaseOxmlElement

w:bookmarkStart element, the opening delimiter of a named range.

bookmarkEnd property

bookmarkEnd: CT_BookmarkEnd | None

The w:bookmarkEnd matching this start, or None when there is none.

An unmatched start is common enough in documents produced by other tools that it is reported rather than raised on.

CT_BookmarkEnd

Bases: BaseOxmlElement

w:bookmarkEnd element, the closing delimiter of a named range.

is_hidden_bookmark_name

is_hidden_bookmark_name(name: str) -> bool

True for a bookmark Word maintains for itself rather than one a user made.

Source code in src/docx/oxml/bookmark.py
def is_hidden_bookmark_name(name: str) -> bool:
    """True for a bookmark Word maintains for itself rather than one a user made."""
    return name.startswith(_HIDDEN_BOOKMARK_PREFIXES)