Files
Dylan M. Taylor baf6bd58f0 Add craft-flow: the flow model the text formats map to (#1025)
* Add craft-wordmodel: WordCraft's document model without its editing code

WordCraft's crates/doc (wordcraft-doc, at 07f97737) moved as it is, so the DOCX,
RTF, ODT and other text-format crates can read into and write from one model.
Module paths, type names and serde attributes are unchanged: an app that
re-exports the crate keeps its native file format.

Left in the app: range editing (edit.rs), IME text and equation editing. Not
model, and already in craft-libs: code pages (craft-rtf), the ZIP entry-count
check (craft-opc), the compound-file guard (craft-cfb). The paragraph walks
moved to walk.rs and the unit helpers of wordcraft-geom to geom.rs.

* craft-wordmodel: math_tree, the arguments of an equation node and a walk over its runs

The DOCX reader and writer walk an equation's runs. The walk and the child
accessors it uses were in WordCraft's equation editor (math_edit.rs), which
stays in the app; they are structure, not editing.

* craft-wordmodel: keep the document operations (edit.rs) with the model

The DOCX and RTF readers use them: alternative-format chunks are merged into
a document with adopt_blocks, and a reader formats ranges with format_range
and inserts objects. They operate on the document, not on a view, so they
belong beside it. The tests that drove them come back with them; the
paragraph walks stay in walk.rs and edit re-exports them.

base64 0.23, as WordCraft and craft-offcrypto use.

* Add craft-flow: the flow model the text formats map to, on craft-wordmodel

WordCraft's crates/formats/src/model (07f97737) moved as it is: Flow,
FBlock, Para, Inline, Fmt, tables and cells, pictures, to_doc and
from_doc, picture sniffing, colours, base64 and the Dropped report. Only
the paths changed (wordcraft_doc is craft_wordmodel); the report helpers
are public so the format crates can call them; the image re-encoding
helper stays with WordCraft's RTF writer.
2026-11-11 20:41:34 -05:00
..

craft-flow

The model every text format maps to and from: a Flow is blocks, a block a paragraph (Para: a Kind — normal, heading, title, quote, code line, rule — list membership, alignment, spacing and formatted Inline spans: text, pictures, links, bookmarks, fields, notes, equations, ruby, charts, shapes) or a table (FTable of Cells holding blocks), with the document's Meta.

to_doc and from_doc convert a flow to and from a craft_wordmodel::Document. A format reader builds a flow and calls to_doc; a writer calls from_doc (or from_doc_with and FlowOpts for what that format keeps: fields, boxes, paragraph formatting, tracked changes) and walks the flow. Formats that keep more than the flow holds (ODT) carry it in the optional fields (extra, kept, …), which the plain formats leave empty.

use craft_flow::{FBlock, Flow, Fmt, Inline, Kind, Para, from_doc, to_doc};

let p = Para { kind: Kind::Heading(1), inlines: vec![Inline::Text("Title".into(), Fmt::default())], ..Default::default() };
let doc = to_doc(&Flow { blocks: vec![FBlock::Para(p)], ..Default::default() });
let back = from_doc(&doc);
assert!(matches!(&back.blocks[..], [FBlock::Para(p)] if p.kind == Kind::Heading(1) && p.text() == "Title"));

Also here: picture sniffing and sizing (sniff_image, image_px, make_img), CSS colours (parse_color), base64 and data: URIs, list labels (ListCounter), and the one-warning-per-kind report of what an importer leaves out to stay within a limit (Dropped, begin_import, dropped).

Provenance

WordCraft's crates/formats/src/model (at 07f97737), moved as it is onto craft-wordmodel. Image decoding for re-encoding (decode_bounded) stays with the RTF writer that needs it.