Skip to content

docx_plus.revisions.accept

Resolve revision marks into final text. Accepting keeps the recorded edit; rejecting restores the pre-edit state. Run-level insertions and deletions are handled fully (insertion accept = unwrap, deletion accept = remove, and the inverses on reject, restoring <w:delText> to live <w:t>). Move and property-change marks get a safe, non-structural transform; the one structural case — a paragraph-mark deletion implies a paragraph merge — ships a non-corrupting fallback that drops the mark and leaves the text intact (true merge/split is deferred).

The *_all forms process revisions innermost-first so nested marks resolve before their containers, and are idempotent on a clean document.

docx_plus.revisions.accept

Accept or reject tracked changes — resolve revision marks into final text.

Accepting a revision keeps the edit it records; rejecting restores the pre-edit state. The transform differs per element type:

================ ========================== =========================== Element Accept Reject ================ ========================== =========================== w:ins unwrap (keep runs) remove (drop element+runs) w:del remove unwrap + w:delTextw:t w:moveFrom remove unwrap (+ retag) w:moveTo unwrap remove move markers remove remove w:rPrChange remove marker restore recorded old w:rPr w:pPrChange remove marker restore recorded old w:pPr para-mark ins/del remove mark (safe) remove mark (safe) ================ ========================== ===========================

Run-level insertions and deletions are handled fully. Move and property-change marks get the safe, non-structural transform above. The one genuinely structural case — accepting a paragraph-mark deletion should merge two paragraphs — ships a non-corrupting fallback (the mark is removed, the text is left intact) rather than attempting the merge; true merge/split is deferred (ROADMAP v0.3+).

This module imports only from docx_plus.core and the sibling docx_plus.revisions.mark (SPEC §9.1).

accept_revision

accept_revision(doc: Document, revision_id: int) -> None

Accept the revision(s) with revision_id, keeping the recorded edit.

Locates every body element carrying @w:id == revision_id and applies the per-type accept transform. To fully resolve a move (whose wrapper and range markers carry distinct ids) prefer :func:accept_all_revisions.

Parameters:

Name Type Description Default
doc Document

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

required
revision_id int

The w:id of the revision to accept.

required

Raises:

Type Description
RevisionNotFoundError

If no revision element carries revision_id. Subclasses :class:KeyError.

Source code in docx_plus/revisions/accept.py
def accept_revision(doc: Document, revision_id: int) -> None:
    """Accept the revision(s) with ``revision_id``, keeping the recorded edit.

    Locates every body element carrying ``@w:id == revision_id`` and applies
    the per-type accept transform. To fully resolve a *move* (whose wrapper
    and range markers carry distinct ids) prefer
    :func:`accept_all_revisions`.

    Args:
        doc: The python-docx :class:`~docx.document.Document` to mutate.
        revision_id: The ``w:id`` of the revision to accept.

    Raises:
        RevisionNotFoundError: If no revision element carries ``revision_id``.
            Subclasses :class:`KeyError`.
    """
    _resolve_by_id(doc, revision_id, accept=True)

reject_revision

reject_revision(doc: Document, revision_id: int) -> None

Reject the revision(s) with revision_id, restoring the prior state.

Parameters:

Name Type Description Default
doc Document

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

required
revision_id int

The w:id of the revision to reject.

required

Raises:

Type Description
RevisionNotFoundError

If no revision element carries revision_id.

Source code in docx_plus/revisions/accept.py
def reject_revision(doc: Document, revision_id: int) -> None:
    """Reject the revision(s) with ``revision_id``, restoring the prior state.

    Args:
        doc: The python-docx :class:`~docx.document.Document` to mutate.
        revision_id: The ``w:id`` of the revision to reject.

    Raises:
        RevisionNotFoundError: If no revision element carries ``revision_id``.
    """
    _resolve_by_id(doc, revision_id, accept=False)

accept_all_revisions

accept_all_revisions(doc: Document) -> None

Accept every tracked change in doc.

Idempotent: a document with no revisions is left unchanged. Revisions are processed innermost-first so a nested revision is resolved before its container.

Parameters:

Name Type Description Default
doc Document

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

required
Source code in docx_plus/revisions/accept.py
def accept_all_revisions(doc: Document) -> None:
    """Accept every tracked change in ``doc``.

    Idempotent: a document with no revisions is left unchanged. Revisions
    are processed innermost-first so a nested revision is resolved before
    its container.

    Args:
        doc: The python-docx :class:`~docx.document.Document` to mutate.
    """
    _resolve_all(doc, accept=True)

reject_all_revisions

reject_all_revisions(doc: Document) -> None

Reject every tracked change in doc, restoring the pre-edit text.

Idempotent. Revisions are processed innermost-first.

Parameters:

Name Type Description Default
doc Document

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

required
Source code in docx_plus/revisions/accept.py
def reject_all_revisions(doc: Document) -> None:
    """Reject every tracked change in ``doc``, restoring the pre-edit text.

    Idempotent. Revisions are processed innermost-first.

    Args:
        doc: The python-docx :class:`~docx.document.Document` to mutate.
    """
    _resolve_all(doc, accept=False)