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