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