Skip to content

docx_plus.comments.registry

Per-document registry of issued comment w:id values. Comment ids live in a separate uniqueness namespace from SDT, bookmark, and note ids — comment 5 does not collide with bookmark 5. The registry seeds itself from both the comments part and any orphaned body-side range markers so partially-deleted comments can't trigger id reuse.

docx_plus.comments.registry

Comment-id registry.

Comment w:id lives in a separate uniqueness namespace from SDT ids, bookmark ids, and note ids (a comment with id 5 does not collide with a bookmark with id 5). This module ships a tiny subclass of :class:~docx_plus.core.ids._IdRegistryBase that seeds itself from the comment ids already present in comments.xml and from any orphaned body-side markers (w:commentRangeStart, w:commentRangeEnd, w:commentReference) still in the body. The latter matters because hand-edited or partially-deleted documents can leave any one of those markers behind on its own, and it should still block id reuse.

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

CommentIdRegistry

CommentIdRegistry(doc: Document)

Bases: _IdRegistryBase

Tracks issued comment w:id values for one document-edit session.

Source code in docx_plus/core/ids.py
def __init__(self, doc: Document) -> None:
    """Scan ``doc`` for IDs already issued in this namespace.

    Args:
        doc: A python-docx :class:`~docx.document.Document`.
    """
    self._issued: set[int] = set()
    self._seed_from_document(doc)