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//! - **Diff / apply** structural change lists between two trees:
16//! [`Node::diff`], [`apply`].
17//! - **Extract** text: [`Node::text_content`], [`Node::word_count`].
18//! - **Validate** (opt-in) against a schema: [`Node::validate`], [`Schema`].
19//! - **Build** nodes ergonomically: [`Node::element`], [`Node::text`], [`doc`].
20//!
21//! ```
22//! use tiptap_rusty_parser::{Document, Mark, Node};
23//!
24//! let mut doc = Document::from_json_str(
25//! r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
26//! )
27//! .unwrap();
28//!
29//! // Bold every text node.
30//! doc.replace_all(
31//! |n| n.node_type.as_deref() == Some("text"),
32//! |n| { n.add_mark(Mark::new("bold")); },
33//! );
34//!
35//! // Append a new paragraph.
36//! doc.push_child(Node::element("paragraph").with_text("bye"));
37//!
38//! assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);
39//! ```
40
41mod builder;
42mod diff;
43mod document;
44mod error;
45mod mutate;
46mod node;
47mod path;
48mod query;
49mod schema;
50mod select;
51mod text;
52
53pub use builder::doc;
54pub use diff::{apply, diff, ApplyError, Change};
55pub use document::Document;
56pub use error::{ParseError, Result};
57pub use node::{Mark, Node};
58pub use query::Descendants;
59pub use schema::{MarkSpec, NodeSpec, Schema, Violation, ViolationKind};