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`]; or by flat
13//!   ProseMirror integer position: [`Node::resolve`], [`Node::pos_before`], [`ResolvedPos`].
14//! - **Mutate** in place: marks, attrs, children, text, and bulk
15//!   [`Node::replace_all`].
16//! - **Normalize** to a canonical form (merge adjacent text, drop empties):
17//!   [`Node::normalize`], [`NormalizeOptions`].
18//! - **Range-edit** a block's inline content (insert/delete/replace text, mark
19//!   ranges): [`Node::insert_text`], [`Node::add_mark_range`], [`Position`], [`Range`].
20//! - **Restructure** the block tree (split/join/wrap/lift/retype):
21//!   [`Node::split_block`], [`Node::join_blocks`], [`Node::wrap`], [`Node::lift`], [`BlockRange`].
22//! - **Diff / apply / invert** structural change lists between two trees
23//!   (undo-capable): [`Node::diff`], [`apply`], [`invert`].
24//! - **Transact**: mutate in place while recording a replayable/invertible
25//!   change log: [`Node::transform`], [`Transform`].
26//! - **Operate on change lists**: [`compose`], [`compact`], and carry a path
27//!   through edits with [`map_path`].
28//! - **Extract** text: [`Node::text_content`], [`Node::word_count`].
29//! - **Validate** (opt-in) against a schema, incl. ProseMirror content
30//!   expressions: [`Node::validate`], [`Schema`], [`ContentExpr`].
31//! - **Render** to HTML: [`Node::to_html`], [`HtmlOptions`].
32//! - **Build** nodes ergonomically: [`Node::element`], [`Node::text`], [`doc`].
33//!
34//! ```
35//! use tiptap_rusty_parser::{Document, Mark, Node};
36//!
37//! let mut doc = Document::from_json_str(
38//!     r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
39//! )
40//! .unwrap();
41//!
42//! // Bold every text node.
43//! doc.replace_all(
44//!     |n| n.node_type.as_deref() == Some("text"),
45//!     |n| { n.add_mark(Mark::new("bold")); },
46//! );
47//!
48//! // Append a new paragraph.
49//! doc.push_child(Node::element("paragraph").with_text("bye"));
50//!
51//! assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);
52//! ```
53
54mod block;
55mod builder;
56mod change_ops;
57mod content;
58mod diff;
59mod document;
60mod error;
61mod html;
62mod mutate;
63mod node;
64mod normalize;
65mod path;
66mod pos;
67mod query;
68mod range;
69mod schema;
70mod select;
71mod text;
72mod transform;
73
74pub use block::{BlockError, BlockRange};
75pub use builder::doc;
76pub use change_ops::{compact, compose, map_path};
77pub use content::{ContentExpr, ContentRule, ParseExprError};
78pub use diff::{apply, diff, invert, ApplyError, Change};
79pub use document::Document;
80pub use error::{ParseError, Result};
81pub use html::{to_html, HtmlOptions, SelfClosingStyle, UnknownMarkPolicy, UnknownNodePolicy};
82pub use node::{Mark, Node};
83pub use normalize::NormalizeOptions;
84pub use pos::{LeafPolicy, PosError, PosRange, ResolvedPos, TextPoint};
85pub use query::Descendants;
86pub use range::{Position, Range, RangeError};
87pub use schema::{MarkSpec, NodeSpec, Schema, Violation, ViolationKind};
88pub use transform::Transform;