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//! - **Render** to HTML: [`Node::to_html`], [`HtmlOptions`].
21//! - **Build** nodes ergonomically: [`Node::element`], [`Node::text`], [`doc`].
22//!
23//! ```
24//! use tiptap_rusty_parser::{Document, Mark, Node};
25//!
26//! let mut doc = Document::from_json_str(
27//! r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
28//! )
29//! .unwrap();
30//!
31//! // Bold every text node.
32//! doc.replace_all(
33//! |n| n.node_type.as_deref() == Some("text"),
34//! |n| { n.add_mark(Mark::new("bold")); },
35//! );
36//!
37//! // Append a new paragraph.
38//! doc.push_child(Node::element("paragraph").with_text("bye"));
39//!
40//! assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);
41//! ```
42
43mod builder;
44mod content;
45mod diff;
46mod document;
47mod error;
48mod html;
49mod mutate;
50mod node;
51mod path;
52mod query;
53mod schema;
54mod select;
55mod text;
56
57pub use builder::doc;
58pub use content::{ContentExpr, ContentRule, ParseExprError};
59pub use diff::{apply, diff, invert, ApplyError, Change};
60pub use document::Document;
61pub use error::{ParseError, Result};
62pub use html::{to_html, HtmlOptions, SelfClosingStyle, UnknownMarkPolicy, UnknownNodePolicy};
63pub use node::{Mark, Node};
64pub use query::Descendants;
65pub use schema::{MarkSpec, NodeSpec, Schema, Violation, ViolationKind};