Expand description
§tiptap-rusty-parser
Fast, schema-agnostic parser and manipulator for Tiptap / ProseMirror
JSONContent documents.
- Parse / serialize via
Document(faithful roundtrip, unknown fields preserved). - Query with predicate closures:
Node::find,Node::find_all,Node::walk,Node::descendants. - Select by type/mark/attr:
Node::by_type,Node::by_mark,Node::by_attr. - Address by index path:
Node::node_at,Node::path_to. - Mutate in place: marks, attrs, children, text, and bulk
Node::replace_all. - Normalize to a canonical form (merge adjacent text, drop empties):
Node::normalize,NormalizeOptions. - Range-edit a block’s inline content (insert/delete/replace text, mark
ranges):
Node::insert_text,Node::add_mark_range,Position,Range. - Restructure the block tree (split/join/wrap/lift/retype):
Node::split_block,Node::join_blocks,Node::wrap,Node::lift,BlockRange. - Diff / apply / invert structural change lists between two trees
(undo-capable):
Node::diff,apply,invert. - Transact: mutate in place while recording a replayable/invertible
change log:
Node::transform,Transform. - Operate on change lists:
compose,compact, and carry a path through edits withmap_path. - Extract text:
Node::text_content,Node::word_count. - Validate (opt-in) against a schema, incl. ProseMirror content
expressions:
Node::validate,Schema,ContentExpr. - Render to HTML:
Node::to_html,HtmlOptions. - Build nodes ergonomically:
Node::element,Node::text,doc.
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§
- Apply
Error - Error from
applywhen a change can’t be located (no node at the path, or a child index out of range). Lists produced bydiffnever fail. - Block
Range - A contiguous run of sibling blocks
[start, end)under a common parent. - Content
Expr - 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"). - Html
Options - Options controlling HTML rendering.
Defaultmatches Tiptap conventions. - Mark
- A mark applied to a node (e.g.
bold,italic,link). - Mark
Spec - Rules for one mark type.
- Node
- A single Tiptap/ProseMirror node.
- Node
Spec - Rules for one node type.
- Normalize
Options - Options controlling
Node::normalize_with.Defaultis the sensible hygiene pass: merge adjacent text and drop empty text, but keep empty nodes (an empty paragraph is structurally valid). - Parse
Expr Error - Error parsing (or compiling) a content expression.
- Position
- A position in a block’s inline content: a
childindex plus a Unicode-scalaroffsetinto that child’s text. For a non-text child,offsetmust be0(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 <= endin document order). - Schema
- An allow-list schema: which node/mark types, attributes, and children are
permitted. Build with
Schema::newor load withSchema::from_json_str. - Transform
- A mutation transaction over a
Nodetree: edits apply in place and are recorded as aChangelog. Create withNode::transform. - Violation
- A single schema violation, located by the offending node’s index path.
Enums§
- Block
Error - Why a block-structural operation could not be applied.
- Change
- A single structural change between two
Nodetrees. - Content
Rule - A node’s allowed content: a set of child types (array form) or an ordered content expression (string form).
- Parse
Error - Errors produced while parsing or serializing a document.
- Range
Error - Why a range operation could not be applied.
- Self
Closing Style - Whether void elements self-close (
<br/>) or use the HTML5 form (<br>). - Unknown
Mark Policy - How to render a mark whose type has no built-in or configured mapping.
- Unknown
Node Policy - How to render a node whose type has no built-in or configured mapping.
- Violation
Kind - The kinds of schema violation.
Functions§
- apply
- Apply a
Changelist torootin order, mutating it in place. - compact
- Coalesce redundant changes while preserving the
applyresult. Only safe reductions are performed: - compose
- A change list apply-equivalent to running
athenb. - diff
- Structural diff between two nodes. Free-function form of
Node::diff. - doc
- Build a
docroot node from its children. - invert
- Invert a change list: produce the reverse changes that, applied to the
result of
apply(base, changes), restorebase— the basis for undo. - map_
path - Carry an index-path through a change list: where does the node originally at
pathend up after applyingchanges? ReturnsNoneif 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.