docx-redline v1.0.2

Every example, run live

26 examples covering every option in the library. Each one is executed when you open it, and the .docx it writes is rendered below it โ€” insertions, deletions, moves, formatting revisions and comments, straight from the OOXML.

Legend inserted deleted moved formatting 1 comment

Layer 1 ยท Redliner

Targeted, scripted edits: you know the paragraph.

01 Quickstart โ€” the smallest useful redline

Four edits, one save. Everything else in this folder is a variation on this.

02 Every Redliner constructor option

Redliner(source, author="Redline", initials=None, date=None, track_changes=True, scope=("body", "headers", "footers", "notes"))

03 Locating what to edit

find_paragraphs(contains, regex, style, startswith, ignore_case, include_tables) find_paragraph(...) exactly one, or raises find_text(needle, regex, ignore_case, limit) text_of(paragraph) the view every other method uses

04 Inserting and deleting text

insert_text(paragraph, offset, text) insert_text_before(needle, text, **kw) insert_text_after(needle, text, **kw) append_text(paragraph, text) delete_text(paragraph, start, end) delete_matching(needle, regex=False, ignore_case=False, count=None)

05 Replacing text โ€” every option

replace_text(old, new, regex=False, ignore_case=False, count=1, insertion_first=False) set_paragraph_text(paragraph, new_text, ignore_case=False)

06 Whole paragraphs: insert, delete, move

insert_paragraph_before/after(reference, text="", style=None, copy_format=True) append_paragraph(text, style=None) delete_paragraph(paragraph) delete_paragraphs(paragraphs) move_paragraph(paragraph, after) relocate_paragraph(source, after=None, before=None) apply_style(paragraph, name)

07 Tables

tables() insert_table_row(table, index=None, values=None) delete_table_row(table, index) delete_row(row) set_cell_text(cell, new_text)

08 Formatting revisions โ€” w:rPrChange and w:pPrChange

format_runs(runs, **props) format_matching(needle, regex=False, count=None, **props) format_paragraph_text(paragraph, **props) format_paragraph(paragraph, **props)

09 Comments

add_comment(paragraph, text, runs=None, author=None, initials=None)

10 Reviewing what is already there

summary() -> RevisionSummary accept_all() / reject_all() -> Redliner accept_file(src, out) / reject_file(src, out) summarize(root, part=...) the module-level form

Layer 2 ยท ParagraphIndex

Stable paragraph ids and quoted spans, verified before anything is written.

Layer 3 ยท Action items

A model restructures the document; numbering and references follow.

Other surfaces

Compare, op plans, structure, the CLI, errors.