tiptap-rusty-parser 0.6.2

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

tiptap-rusty-parser

A fast, schema-agnostic Rust crate to parse, query, edit, diff and validate Tiptap / ProseMirror JSONContent documents.

  • Any schema. Every node and mark type is accepted. A schema is optional and only used when you validate.
  • Faithful roundtrip. Unknown node types and unknown JSON fields are kept and written back.
  • Fast. Queries return borrows instead of clones, and edits happen in place.

It is the engine behind Tiptap Studio, and is also published for JavaScript as @tiptap-studio/rusty-parser.

Documentation: guide · API reference

Install

[dependencies]
tiptap-rusty-parser = "0.6"

Quick start

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

let mut doc = Document::from_json_str(
    r#"{"type":"doc","content":[
        {"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Notes"}]},
        {"type":"paragraph","content":[{"type":"text","text":"hello"}]}
    ]}"#,
)
.unwrap();

// Query with a closure, or with the query language.
assert_eq!(doc.by_type("paragraph").len(), 1);
let q = Query::parse("type == heading && attrs.level == 1").unwrap();
assert_eq!(q.find_paths(doc.root()), vec![vec![0]]);

// Bold every text node and append a paragraph.
let changed = doc.replace_all(
    |n| n.node_type.as_deref() == Some("text"),
    |n| {
        n.add_mark(Mark::new("bold"));
    },
);
assert_eq!(changed, 2);
doc.push_child(Node::element("paragraph").with_text("bye"));

assert_eq!(doc.text_content_with_separator("\n"), "Notes\nhello\nbye");

What it does

Area Guide
Parse and serialize, with source maps from nodes to JSON byte spans Parsing
Find nodes with closures, selectors or a query language (type == heading && attrs.level > 1) Querying, Query language
Address nodes by index path or by ProseMirror position, and map positions through edits Paths and positions
Edit marks, attributes, children and text; normalize; range and block commands Mutating, Range and block editing
Record edits as an invertible change log for undo Transactions
Apply position-addressed edits, as AI tools produce them Position editing
Diff two documents into a change list; compose, compact, map and cherry-pick changes Diffing, Change algebra
Validate against a schema with ProseMirror-style content expressions Schema
Extract text, render HTML, build nodes in code Text, HTML, Building nodes

Upgrading from 0.5: see the migration guide.

License

MIT