Skip to main content

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