Skip to content

docx_plus.revisions.registry

Per-document registry of issued revision w:id values. Unlike comments, bookmarks, and notes — each of which has its own id namespace — all tracked-change element types (w:ins, w:del, the move wrappers and their range markers, w:rPrChange, w:pPrChange) share a single w:id namespace, so a w:ins and a w:del cannot reuse the same id. The registry seeds itself from every revision-bearing element in the body.

docx_plus.revisions.registry

Revision-id registry.

Unlike SDT, bookmark, comment, and note ids — each of which lives in its own uniqueness namespace — all tracked-change revision elements share a single w:id namespace. A <w:ins w:id="5"> and a <w:del w:id="5"> in the same document collide; so do a w:moveFrom and a w:rPrChange that reuse an id. This module ships a subclass of :class:~docx_plus.core.ids._IdRegistryBase that seeds itself from every revision-bearing element in the document body so :meth:next never reissues an id already in use by any revision type.

The .// descendant axis deliberately reaches revision marks nested inside w:pPr / w:rPr (paragraph-mark insertions and deletions), not just the run-level ones, so those block reuse too.

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

RevisionIdRegistry

RevisionIdRegistry(doc: Document)

Bases: _IdRegistryBase

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

All tracked-change element types draw from one shared id namespace, so this registry seeds from every revision tag in the body — run-level insertions/deletions, move wrappers and their range markers, and the property-change markers (including the paragraph-mark variants nested in w:pPr / w:rPr).

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)