tiptap_rusty_parser/lib.rs
1//! # tiptap-rusty-parser
2//!
3//! Fast, schema-agnostic parser and manipulator for Tiptap / ProseMirror
4//! `JSONContent` documents.
5//!
6//! - **Parse / serialize** via [`Document`] (faithful roundtrip, unknown fields
7//! preserved).
8//! - **Query** with predicate closures: [`Node::find`], [`Node::find_all`],
9//! [`Node::walk`], [`Node::descendants`].
10//! - **Select** by type/mark/attr: [`Node::by_type`], [`Node::by_mark`],
11//! [`Node::by_attr`].
12//! - **Address** by index path: [`Node::node_at`], [`Node::path_to`].
13//! - **Mutate** in place: marks, attrs, children, text, and bulk
14//! [`Node::replace_all`].
15//! - **Normalize** to a canonical form (merge adjacent text, drop empties):
16//! [`Node::normalize`], [`NormalizeOptions`].
17//! - **Range-edit** a block's inline content (insert/delete/replace text, mark
18//! ranges): [`Node::insert_text`], [`Node::add_mark_range`], [`Position`], [`Range`].
19//! - **Diff / apply / invert** structural change lists between two trees
20//! (undo-capable): [`Node::diff`], [`apply`], [`invert`].
21//! - **Extract** text: [`Node::text_content`], [`Node::word_count`].
22//! - **Validate** (opt-in) against a schema, incl. ProseMirror content
23//! expressions: [`Node::validate`], [`Schema`], [`ContentExpr`].
24//! - **Render** to HTML: [`Node::to_html`], [`HtmlOptions`].
25//! - **Build** nodes ergonomically: [`Node::element`], [`Node::text`], [`doc`].
26//!
27//! ```
28//! use tiptap_rusty_parser::{Document, Mark, Node};
29//!
30//! let mut doc = Document::from_json_str(
31//! r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
32//! )
33//! .unwrap();
34//!
35//! // Bold every text node.
36//! doc.replace_all(
37//! |n| n.node_type.as_deref() == Some("text"),
38//! |n| { n.add_mark(Mark::new("bold")); },
39//! );
40//!
41//! // Append a new paragraph.
42//! doc.push_child(Node::element("paragraph").with_text("bye"));
43//!
44//! assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);
45//! ```
46
47mod builder;
48mod content;
49mod diff;
50mod document;
51mod error;
52mod html;
53mod mutate;
54mod node;
55mod normalize;
56mod path;
57mod query;
58mod range;
59mod schema;
60mod select;
61mod text;
62
63pub use builder::doc;
64pub use content::{ContentExpr, ContentRule, ParseExprError};
65pub use diff::{apply, diff, invert, ApplyError, Change};
66pub use document::Document;
67pub use error::{ParseError, Result};
68pub use html::{to_html, HtmlOptions, SelfClosingStyle, UnknownMarkPolicy, UnknownNodePolicy};
69pub use node::{Mark, Node};
70pub use normalize::NormalizeOptions;
71pub use query::Descendants;
72pub use range::{Position, Range, RangeError};
73pub use schema::{MarkSpec, NodeSpec, Schema, Violation, ViolationKind};