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