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//! - **Mutate** in place: marks, attrs, children, text, and bulk
11//! [`Node::replace_all`].
12//! - **Build** nodes ergonomically: [`Node::element`], [`Node::text`], [`doc`].
13//!
14//! ```
15//! use tiptap_rusty_parser::{Document, Mark, Node};
16//!
17//! let mut doc = Document::from_json_str(
18//! r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
19//! )
20//! .unwrap();
21//!
22//! // Bold every text node.
23//! doc.replace_all(
24//! |n| n.node_type.as_deref() == Some("text"),
25//! |n| { n.add_mark(Mark::new("bold")); },
26//! );
27//!
28//! // Append a new paragraph.
29//! doc.push_child(Node::element("paragraph").with_text("bye"));
30//!
31//! assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);
32//! ```
33
34mod builder;
35mod document;
36mod error;
37mod mutate;
38mod node;
39mod query;
40
41pub use builder::doc;
42pub use document::Document;
43pub use error::{ParseError, Result};
44pub use node::{Mark, Node};
45pub use query::Descendants;