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