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