Skip to main content

Crate tiptap_rusty_parser

Crate tiptap_rusty_parser 

Source
Expand description

§tiptap-rusty-parser

Fast, schema-agnostic parser and manipulator for Tiptap / ProseMirror JSONContent documents.

use tiptap_rusty_parser::{Document, Mark, Node};

let mut doc = Document::from_json_str(
    r#"{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"hi"}]}]}"#,
)
.unwrap();

// Bold every text node.
doc.replace_all(
    |n| n.node_type.as_deref() == Some("text"),
    |n| { n.add_mark(Mark::new("bold")); },
);

// Append a new paragraph.
doc.push_child(Node::element("paragraph").with_text("bye"));

assert_eq!(doc.find_all(|n| n.node_type.as_deref() == Some("paragraph")).len(), 2);

Structs§

ApplyError
Error from apply when a change can’t be located (no node at the path, or a child index out of range). Lists produced by diff never fail.
BlockRange
A contiguous run of sibling blocks [start, end) under a common parent.
ContentExpr
A compiled ProseMirror content expression (e.g. paragraph+).
Descendants
Pre-order descendant iterator. See Node::descendants.
DiffOptions
Options for Node::diff_with.
Document
An owned Tiptap document (its root node, usually type: "doc").
HtmlOptions
Options controlling HTML rendering. Default matches Tiptap conventions.
Mark
A mark applied to a node (e.g. bold, italic, link).
MarkSpec
Rules for one mark type.
Node
A single Tiptap/ProseMirror node.
NodeSpec
Rules for one node type.
NormalizeOptions
Options controlling Node::normalize_with. Default is the sensible hygiene pass: merge adjacent text and drop empty text, but keep empty nodes (an empty paragraph is structurally valid).
ParseExprError
Error parsing (or compiling) a content expression.
PosMap
A flat position map over a batch of disjoint replacements, mapping pre-edit positions to post-edit ones. See the module docs.
PosRange
A flat ProseMirror range [from, to] over a whole document. (Distinct from the block-scoped Range used by inline range editing.)
Position
A position in a block’s inline content: a child index plus a Unicode-scalar offset into that child’s text. For a non-text child, offset must be 0 (the boundary before it); the boundary after it is the next child’s offset 0.
Range
A range between two Positions in the same block (start <= end in document order).
ResolvedPos
A flat position resolved against a Node tree. All fields are owned indices (no borrows), so it serializes and crosses FFI cleanly.
Schema
An allow-list schema: which node/mark types, attributes, and children are permitted. Build with Schema::new or load with Schema::from_json_str.
TextPoint
The text node and scalar offset a position falls inside.
TextSegment
A run of characters classified by a text diff.
Transform
A mutation transaction over a Node tree: edits apply in place and are recorded as a Change log. Create with Node::transform.
Violation
A single schema violation, located by the offending node’s index path.

Enums§

Assoc
Which edge a position lying inside a replaced span maps to.
BlockError
Why a block-structural operation could not be applied.
Change
A single structural change between two Node trees.
ContentRule
A node’s allowed content: a set of child types (array form) or an ordered content expression (string form).
DiffGranularity
How Node::diff_with treats changed text nodes.
LeafPolicy
Decides which nodes are ProseMirror leaves (size 1) vs empty containers (size 2). Leafness isn’t recoverable from JSON, so it’s configured here.
ParseError
Errors produced while parsing or serializing a document.
PosContent
Content carried by an PosEdit::Insert / PosEdit::Replace.
PosEdit
A single position-addressed edit. Offsets are flat ProseMirror positions.
PosEditError
Why a Node::apply_pos_edits batch could not be applied.
PosError
Why a flat-position operation failed.
RangeError
Why a range operation could not be applied.
SegKind
One segment of a character-level text diff.
SelfClosingStyle
Whether void elements self-close (<br/>) or use the HTML5 form (<br>).
UnknownMarkPolicy
How to render a mark whose type has no built-in or configured mapping.
UnknownNodePolicy
How to render a node whose type has no built-in or configured mapping.
ViolationKind
The kinds of schema violation.

Functions§

apply
Apply a Change list to root in order, mutating it in place.
compact
Coalesce redundant changes while preserving the apply result. Only safe reductions are performed:
compose
A change list apply-equivalent to running a then b.
diff
Structural diff between two nodes. Free-function form of Node::diff.
diff_text
Character-level (Unicode-scalar) diff of two strings.
doc
Build a doc root node from its children.
invert
Invert a change list: produce the reverse changes that, applied to the result of apply(base, changes), restore base — the basis for undo.
map_path
Carry an index-path through a change list: where does the node originally at path end up after applying changes? Returns None if it was removed or replaced away.
to_html
Render a node to an HTML string. Free-function form of Node::to_html.

Type Aliases§

Result
Crate result alias.