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