quillmark_content/lib.rs
1//! `Content` — the canonical content model for Quillmark (issue #831).
2//!
3//! One [`Content`] per content field: a single text sequence carrying line
4//! attributes, anchored marks, and embedded islands, over one coordinate space
5//! of Unicode scalar values. Markdown is demoted to a *projection* — import
6//! ([`import::from_markdown`]) and export ([`export::to_markdown`]) codecs — so
7//! every edit is a splice and all structure moves with it.
8//!
9//! `core`, `quillmark`, and both backends (`typst`, `pdfform`) consume this
10//! crate: the seam carries content JSON, storage embeds it structurally (see
11//! `prose/canon/DOCUMENT_STORAGE.md`), and the content edit surface
12//! (`delta`, `ops`) drives per-field splices.
13//!
14//! ## Layout
15//!
16//! - [`model`] — the [`Content`] type, the mark set, normalization (the three
17//! Spike-A rules), and invariants. The freeze.
18//! - [`serial`] — canonical, byte-deterministic JSON. One encoding for the seam
19//! and for storage.
20//! - [`island`] — [`KnownIslandType`], the closed dispatch authority for island
21//! types; adding a type is one variant and the compiler enforces every arm.
22//! - [`import`] — markdown → content (normalize → pulldown → content).
23//! - [`export`] — content → markdown, per island loss class.
24//! - [`delta`] — the per-field edit surface: a text-splice change set
25//! (`retain`/`insert`/`delete`, CodeMirror `ChangeSet` semantics) plus the
26//! cold-parse + content-diff stale-text writer with a block-move detector. The
27//! text-splice channel is the positional core; mark and line-attribute edits
28//! are separate op channels, not op attributes — see [`delta`].
29//! - [`ops`] — mark and line op channels:
30//! [`Content::apply_text_delta`], [`apply_mark_ops`](Content::apply_mark_ops),
31//! [`apply_line_ops`](Content::apply_line_ops).
32//! - [`normalize`] — the markdown-string input primitive (line endings, bidi
33//! strip, HTML-comment fence repair), applied at the import boundary.
34//! - [`usv`] — USV → UTF-8 byte-offset conversion for slicing the content.
35
36pub mod delta;
37pub mod export;
38pub mod import;
39pub mod island;
40pub mod model;
41pub mod normalize;
42pub mod ops;
43pub mod serial;
44pub mod usv;
45
46pub use delta::{diff_import, Assoc, Delta, Op};
47pub use export::{to_markdown, to_plaintext};
48pub use import::{from_markdown, from_plaintext};
49pub use island::KnownIslandType;
50pub use model::{
51 Container, Invariant, Island, Line, LineKind, Loss, Mark, MarkKind, Content, Usv,
52};
53pub use normalize::normalize_markdown;
54pub use ops::{
55 change_bundle_from_value, line_op_from_value, line_op_to_value, mark_op_from_value,
56 mark_op_to_value, ApplyError, LineOp, MarkOp,
57};
58pub use serial::ParseError;
59
60/// Maximum container nesting depth the markdown codecs accept before erroring.
61/// The import guard ([`import::from_markdown`]) and the typst backend's markup
62/// converter share this one limit (the backend re-exports it via
63/// `quillmark_core::error::MAX_NESTING_DEPTH`), so a document that imports also
64/// renders.
65pub const MAX_NESTING_DEPTH: usize = 100;