Files
craft-libs/crates/wordmodel
ruchirguitarandClaude Opus 5.5 5b571e5254 Write history on for app-made links and cut settings merge back to w: compat cases
Review of storytold/craft-libs#3361 (bflatastic):

1. Links that didn't come from a .docx file lost w:history="1". Replace
   CharProps::link_history: Option<bool> with Option<LinkHistory>
   (Off, Omitted), set only by the .docx reader. None, which every
   other link has and which the reader also gives a link with history
   on, is written as w:history="1", as main does, so such a link reads
   back unchanged. Text with no value takes the history of the link it
   is in, so typing into a link doesn't split it. New test: a link made
   with a CharProps patch saves with w:history="1". main's
   picture_links test is back to expecting w:history="1".

2. settings_merge.rs is main's file plus a short merge_compat for the
   w:-prefixed cases real files have: the owned switches come from the
   generated part at their CT_Compat position, compatibilityMode is
   replaced, added or removed, and a block left empty goes. The rest
   (aliased and rebound prefixes, Strict and r:* relationship markup,
   escaped names, BOMs and comments, vendor markup on switches) is
   kept with its 22 tests on the fork branch
   docx-settings-merge-hardening (079da658b) for a later PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:00:47 +05:30
..

craft-wordmodel

A word-processing document model: stories, paragraphs, runs, tables, sections, styles, numbering, fields, content controls, notes, comments, revisions, floating objects, drawings and math. It is what the DOCX, RTF, ODT and other text-format crates read into and write from.

It is WordCraft's document model (crates/doc), moved without its editing code. Module paths, type names and serde attributes are as they were, so an app that re-exports the crate keeps its native file format.

use craft_wordmodel::{Block, Document};

let doc = Document::from_text("One\nTwo");
assert_eq!(doc.body.len(), 2);
assert!(matches!(&*doc.body[0], Block::Para(p) if p.text == "One"));

What is here

  • Document: the body story, secondary stories (parts: headers, footers, notes, comments, text boxes), the style sheet, list definitions, comments, revisions, settings, document properties, media and parts kept from the source file.
  • Block, Paragraph, Run, InlineObject, Table: the content. Paragraph text is UTF-8; an inline object stands in the text as U+FFFC (para::OBJ).
  • props, styles, resolve, numbering, section: formatting and its resolution.
  • math, math_latex, math_linear, math_symbols: the equation tree (MNode) and its linear and LaTeX forms.
  • chart, smart_art, graphic, fill, connector, freeform, wordart, effects, picfx, line_dash: drawing objects as the model holds them. Reading and writing their DrawingML is craft-drawingml's job, in the format crates.
  • kept: markup kept from the file a document was read from, so what is not edited is written back as it was.
  • walk, work, geom, bidi, cluster, collate, locale_number, symbol_fonts.

Not here

Range editing, copy and paste, IME text and equation editing stay with the app that edits. Code pages are craft-rtf's codepage, the ZIP entry-count check is craft-opc's.

Limits

The model carries the limits its readers rely on: nesting of tables (table::MAX_TABLE_DEPTH), text boxes (MAX_TEXT_BOX_DEPTH, BoxBudget), math (math::MAX_DEPTH, matrix sizes), group children, alt text length, linked boxes and the walk depth (PARA_WALK_DEPTH). Their tests moved with them.