Skip to main content

Crate jubarte

Crate jubarte 

Source
Expand description

§jubarte

Word-faithful .docx toolkit. It compares two Word documents into a tracked-changes redline that opens cleanly in Microsoft Word, and it also edits, inspects, checks, cleans, merges and renders them: every function takes the complete package as &[u8] and returns a new one, with no temp files and no Word or LibreOffice process.

§What you can do

TaskStart here
Compare two documents into a redlinedocument_comparer::compare_documents; comparer::WmlComparerSettings with document_comparer::compare_documents_with_settings for author, date, moves and detail
List, accept or reject tracked changes, all or somedocument_comparer::get_revisions, document_comparer::accept_revisions, document_comparer::reject_revisions; one at a time with changes::list_changes, changes::accept_changes, changes::reject_changes
Edit a document as tracked changesedit::apply_plan / edit::apply_plan_json with an edit::EditPlan: rewrite, insert, tables, lists, run formatting, footnotes, images, page setup, content controls, watermark, redact, settings
Read a document the way an edit addresses itinspect::paragraphs, inspect::summary, inspect::stories, inspect::controls, inspect::inspect_json, inspect::markdown
Render to PDF or PNGconvert::docx_to_pdf, convert::docx_to_pdf_with and convert::PdfOptions (revision marks: convert::RevisionStyle), convert::docx_to_png; page-by-page differences with convert::diff_render
Convert a Word 97-2003 .doclegacy_doc::doc_to_docx, legacy_doc::doc_to_markdown: text, headings and tables
Markdown in and outmarkdown::markdown_to_docx (CriticMarkup becomes tracked changes and comments), markdown::docx_to_markdown, markdown::diff_markdown, markdown::redline
Check that Word will open it, and repair itvalidate::validate, validate::repair, validate::audit_tracked; triage with debug::report
Accessibility, style and structure findingsaudit::audit_report
Remove authors and metadata before sendingscrub::scrub with scrub::ScrubOptions; find leftover text with scrub::leaks
Append one document after anotherappend::append_documents with append::AppendOptions
List comment threadscomments::list_comments
Refresh a table of contents and other fieldsfields::update_fields
Bound untrusted input before it is openedadmission::admit with admission::InputLimits (every entry point above admits its input too)
Ask what this build supportscapabilities::capabilities_json

The Rust guide walks through each one; the same operations are in Python (jubarte-redlines on PyPI), JavaScript (jubarte-wasm on npm) and the jubarte CLI.

§Example

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let original = std::fs::read("original.docx")?;
    let modified = std::fs::read("modified.docx")?;
    let redline =
        jubarte::document_comparer::compare_documents(&original, &modified, "Reviewer")?;
    std::fs::write("original_v_modified.docx", &redline)?;
    std::fs::write("original_v_modified.pdf", jubarte::convert::docx_to_pdf(&redline)?)?;
    Ok(())
}

An edit plan is JSON, so an agent can write one. Each operation names its paragraph (an id from inspect::paragraphs) and text that must occur there exactly once; the result holds the edited document and its redline:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let contract = std::fs::read("contract.docx")?;
    let plan = r#"{"schema_version": 1, "author": "Reviewer", "operations": [
        {"kind": "replace", "paragraph": "p4",
         "find": "thirty (30) days", "replacement": "sixty (60) days"}
    ]}"#;
    let edited = jubarte::edit::apply_plan_json(&contract, plan)?;
    std::fs::write("contract_clean.docx", &edited.clean)?;
    std::fs::write("contract_redline.docx", &edited.redline)?;
    Ok(())
}

§Comparison fidelity

The redline is Word-valid, and differences in text and formatting are revisions, but the engine also normalizes some markup so the output opens cleanly and matches what Word’s own Compare writes. This list is the main cases, not every one. Both inputs lose non-standard w:-namespace children of w:sdtPr and have mc:AlternateContent resolved to a single branch. In the default (Word-visual) mode, the original’s own tracked changes are flattened and compared like text, internal anchor w:hyperlink wrappers (no r:id) become runs styled as hyperlinks, content controls in any paragraph that carries a revision are unwrapped, some redundant default spacing is stripped, and a breaking and a non-breaking space compare equal (comparer::WmlComparerSettings::conflate_breaking_and_nonbreaking_spaces). comparer::WmlComparerSettings::powertools_faithful skips the mode-specific passes.

§Provenance

The comparer is a Rust port of the WmlComparer/DocumentComparer engine from Docxodus (MIT), itself a fork of Microsoft’s Open-Xml-PowerTools (MIT). The repository itself is Apache-2.0; NOTICE and LICENSES/ preserve those upstream attribution texts.

Modules§

admission
Input admission: budgets, refusal reasons, and the limits types the bindings and CLI expose. Resource admission for untrusted DOCX input: bound the ZIP container before anything inflates it without limits.
append
Append one document after another. Append one document after another: B’s body follows A’s, and what B’s content refers to (images, links, styles, lists, notes, headers) is carried into A’s package under ids that do not collide with A’s.
audit
Accessibility, style and structure findings. jubarte validate --rules a11y,style,structure: accessibility, style and structure findings with the paragraph id an agent can act on.
capabilities
Table, cell and paragraph border views shared by render, markdown and debug. Word’s built-in style names. Machine-readable manifest of what this build can do. What the bindings expose, feature by feature. What this build can do. Agents read it before choosing an operation: jubarte capabilities --json, jubarte_redlines.capabilities().
changes
Tracked changes one at a time: list, accept or reject a selection. Tracked changes one at a time: list, accept or reject a selection. Tracked changes one at a time: list each with an id, accept or reject a selection and keep the rest tracked, as Word’s Accept/Reject This Change does.
cli
The jubarte command’s parser and dispatch. Shared, platform-neutral command declarations and parsing. No runtime I/O.
comments
Comment threads across the parts that hold them. Comment threads: list every comment with its thread position and the text it is anchored to, and write the comment part family whole.
comparer
Custom XML and built-in data stores shared by the OPC layer. Core WmlComparer engine (atomize → LCS → produce → finalize). The comparison core: atomizing, matching, and the redline writer. WmlComparer core (M4). Port of WmlComparer.ts.
comparison_log
Structured comparison log (info / warning / error entries). What a comparison logged, as the CLI prints it. Port of ComparisonLog.ts — diagnostic log emitted during comparison.
convert
Independent DOCX → PDF conversion (not LibreOffice). DOCX to PDF and PNG, with Word-faithful layout. Independent DOCX → PDF, PNG and page-text conversion (no LibreOffice or Word process is involved).
debug
jubarte debug: short Word-validity triage of a package, or two compared. Maintainer triage views. jubarte debug: triage a .docx that Word refuses, or compare two builds of one. Every report is short on purpose. It counts findings by kind, shows a few examples of each (limit), and with two files prints only what differs.
document_comparer
Byte-level package API: compare, list, accept, and reject revisions. One-call document comparison and revision accept/reject. Composed per A6: the compare crate’s module, plus the comment-keeping accept/reject the doc layer owns.
edit
Tracked-change editing: the jubarte-edit crate’s module plus the inline CLI actions (behind cli).
expect
V2-13 (issue #845): the checker core for --expect evaluations. The --expect plan checker. V2-13 (issue #845): the checker core for --expect evaluations.
fields
Refresh a table of contents and other fields (needs render). Refresh the cached results of fields from jubarte’s own layout.
ids
The one grammar of the ids jubarte prints and reads: ShortId (src/ids/short.rs, spec 2026-10-13 §2 and §2.1). The functions here are the options’ views of it: a change (r12, r1+2, header1.r1), a comment (c27), the text a comment covers (c27.text), and what -p takes (a paragraph p12, a story header1 or its paragraph header1.p2, a cell t0.row1.cell2[.p1], a comment, or changes).
inspect
Read-only paragraph/package views and the Markdown projection for agents. Read-only paragraph/package views and the Markdown projection. Read-only views of a DOCX for agents and tools: body paragraphs an edit can address, package facts, and a Markdown projection that carries paragraph ids so the reader’s coordinates are the editor’s coordinates.
legacy_doc
Word 97-2003 .doc reading: text, headings and tables. Word 97-2003 (.doc) to text, paragraphs, headings, lists and tables: the main story, no headers or footers.
markdown
The composed markdown module (A6): the markdown crate’s module plus the edit crate’s patch, redline and unified modules. The composed markdown module (A6): the markdown crate’s module plus this crate’s patch, redline and unified modules, reproducing the facade’s historical markdown from one place.
markup_simplifier
Markup simplification (PowerTools MarkupSimplifier port). Markup simplification (PowerTools MarkupSimplifier port). MarkupSimplifier comparison subset (M2).
namespaces
WordprocessingML and related namespace / XName constants. WordprocessingML and related namespace / XName constants. WordprocessingML and related namespace / XName constants ported from PtOpenXmlUtil.ts (the subset the comparer references) — M1.7.
opc
Open Packaging Conventions adapter (PartFs). Open Packaging Conventions adapter (PartFs). OPC (Open Packaging Conventions) layer — M1.5.
perf
P0-LAB-01 stage counters/timers — no-ops unless perf-profile is enabled. P0-LAB-01 stage counters/timers — no-ops unless perf-profile is enabled. P0-LAB-01 — feature-gated stage counters and coarse timers.
publication
Capability-confined, staged filesystem publication for host applications. Host filesystem publication, capability-confined and staged. Host filesystem publication is unavailable to browser/WASM byte APIs. Stage complete bytes before replacing outputs. A set has one commit per file; errors name any files already committed. No rollback or delete-old fallback is attempted. Native host filesystems only.
result
Stable result codes the bindings print. Machine result envelope for the v2 routes (edit apply, edit template, review accept, and friends).
revision_processor
Accept / reject tracked revisions across a package. Accept and reject tracked revisions across a package. Revision accept / reject pipeline (M3).
scrub
Remove authors and metadata before sending. Remove who touched a document before it goes out, and find where a text still occurs in one.
settings
Settings application (w:settings). Document settings an edit plan writes into word/settings.xml: Track Changes on or off, updateFields on open, and editing restrictions.
strict_translation
ISO Strict → Transitional package normalization. ISO Strict → Transitional package normalization. ISO/IEC 29500 Strict → Transitional namespace normalization (M8).
text_diff
Text diff views (agent view and CriticMarkup). Git/GitHub unified patches of complete document text snapshots, and other review presentations.
unid
Port of UnidHelper (UnidHelper.ts) — M1.7.
update
jubarte self-update: install a GitHub release, only when asked. jubarte self-update: replace this binary with a GitHub release when the user runs jubarte self-update (docs/SELF_UPDATE.md).
util
Shared small utilities. Shared small utilities. Small shared utilities, ported from PtUtil.ts (M1.6).
validate
Check that Word will open a package, and repair it. Word-validity findings beyond the schema: what makes Word refuse or repair a package, as data.
wml_document
Pure DOM structural predicates shared by validate and the comparers. Word’s default theme part, for originals without one. WmlDocument — document bytes + lazily parsed main part. WmlDocument: document bytes plus the lazily parsed main part. Port of WmlDocument / PtMainDocumentPart (WmlDocument.ts) — M1.7.
xmllinq
Arena DOM (xmllinq) used by the comparer. Arena DOM (xmllinq) used by the comparer. LINQ-to-XML-style mutable XML tree, ported from lib/xml-linq.ts.

Structs§

WmlDocument
WmlDocument re-export for the common library entry point. A WordprocessingML document held as its package bytes plus the main document part parsed on demand. Mirrors the C# WmlDocument (DocumentByteArray + lazy MainDocumentPart) used by the crate::comparer pipeline.