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