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