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.
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.
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).
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.
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§

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).
ParseError
Errors produced while parsing or serializing a document.
RangeError
Why a range operation could not be applied.
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.
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.