pub struct Node {
pub node_type: Option<String>,
pub attrs: Option<Map<String, Value>>,
pub content: Option<Vec<Node>>,
pub marks: Option<Vec<Mark>>,
pub text: Option<String>,
pub extra: Map<String, Value>,
}Expand description
A single Tiptap/ProseMirror node.
All structural fields are optional to faithfully distinguish “missing” from
“empty” on roundtrip. Unknown top-level keys land in Node::extra.
Fields§
§node_type: Option<String>Node type, e.g. "doc", "paragraph", "text".
attrs: Option<Map<String, Value>>Node attributes.
content: Option<Vec<Node>>Child nodes.
marks: Option<Vec<Mark>>Marks applied to this node (typically text nodes).
text: Option<String>Text payload (text nodes only).
extra: Map<String, Value>Any unknown/extra top-level fields, preserved verbatim.
Implementations§
Source§impl Node
impl Node
Sourcepub fn element(node_type: impl Into<String>) -> Node
pub fn element(node_type: impl Into<String>) -> Node
Start an element node of node_type (no content/marks/attrs yet).
use tiptap_rusty_parser::Node;
let p = Node::element("paragraph")
.with_attr("textAlign", "center")
.with_text("hello");
assert_eq!(p.child_count(), 1);Sourcepub fn text_with_marks(
text: impl Into<String>,
marks: impl IntoIterator<Item = Mark>,
) -> Node
pub fn text_with_marks( text: impl Into<String>, marks: impl IntoIterator<Item = Mark>, ) -> Node
A text node with text and the given marks.
Sourcepub fn with_attr(self, key: impl Into<String>, value: impl Into<Value>) -> Self
pub fn with_attr(self, key: impl Into<String>, value: impl Into<Value>) -> Self
Builder: set one attr (consuming).
Sourcepub fn with_child(self, node: Node) -> Self
pub fn with_child(self, node: Node) -> Self
Builder: add a child (consuming).
Sourcepub fn with_children(self, nodes: impl IntoIterator<Item = Node>) -> Self
pub fn with_children(self, nodes: impl IntoIterator<Item = Node>) -> Self
Builder: add several children (consuming).
Source§impl Node
impl Node
Sourcepub fn get_mark(&self, mark_type: &str) -> Option<&Mark>
pub fn get_mark(&self, mark_type: &str) -> Option<&Mark>
Reference to the first mark of mark_type.
Sourcepub fn add_mark(&mut self, mark: Mark) -> bool
pub fn add_mark(&mut self, mark: Mark) -> bool
Add mark if no mark of that type exists yet. Returns true if added.
Sourcepub fn remove_mark(&mut self, mark_type: &str) -> usize
pub fn remove_mark(&mut self, mark_type: &str) -> usize
Remove every mark of mark_type. Returns count removed.
Sourcepub fn toggle_mark(&mut self, mark: Mark) -> bool
pub fn toggle_mark(&mut self, mark: Mark) -> bool
Toggle a mark: remove if present, else add. Returns true if now present.
Sourcepub fn set_mark_attr(
&mut self,
mark_type: &str,
key: impl Into<String>,
value: impl Into<Value>,
) -> bool
pub fn set_mark_attr( &mut self, mark_type: &str, key: impl Into<String>, value: impl Into<Value>, ) -> bool
Set an attr on the (first) mark of mark_type. Returns false if absent.
Sourcepub fn clear_marks(&mut self)
pub fn clear_marks(&mut self)
Drop all marks.
Sourcepub fn attrs_mut(&mut self) -> &mut Map<String, Value>
pub fn attrs_mut(&mut self) -> &mut Map<String, Value>
Mutable access to the attrs map, creating it if absent.
Sourcepub fn set_attr(
&mut self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Option<Value>
pub fn set_attr( &mut self, key: impl Into<String>, value: impl Into<Value>, ) -> Option<Value>
Set attr key, returning the previous value if any.
Sourcepub fn remove_attr(&mut self, key: &str) -> Option<Value>
pub fn remove_attr(&mut self, key: &str) -> Option<Value>
Remove attr key, returning its value if present.
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Number of direct children.
Sourcepub fn children_mut(&mut self) -> &mut Vec<Node>
pub fn children_mut(&mut self) -> &mut Vec<Node>
Mutable access to children, creating the vec if absent.
Sourcepub fn push_child(&mut self, node: Node)
pub fn push_child(&mut self, node: Node)
Append a child.
Sourcepub fn insert_child(&mut self, i: usize, node: Node)
pub fn insert_child(&mut self, i: usize, node: Node)
Insert a child at i (clamped to len).
Sourcepub fn remove_child(&mut self, i: usize) -> Option<Node>
pub fn remove_child(&mut self, i: usize) -> Option<Node>
Remove and return the child at i.
Sourcepub fn replace_child(&mut self, i: usize, node: Node) -> Option<Node>
pub fn replace_child(&mut self, i: usize, node: Node) -> Option<Node>
Replace the child at i, returning the old node.
Sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
Remove all children.
Sourcepub fn retain_children(&mut self, pred: impl FnMut(&Node) -> bool)
pub fn retain_children(&mut self, pred: impl FnMut(&Node) -> bool)
Retain only children matching pred.
Source§impl Node
impl Node
Sourcepub fn walk(&self, f: &mut impl FnMut(&Node))
pub fn walk(&self, f: &mut impl FnMut(&Node))
Visit self and every descendant, pre-order.
use tiptap_rusty_parser::Document;
let doc = Document::from_json_str(r#"{"type":"doc","content":[{"type":"paragraph"}]}"#).unwrap();
let mut n = 0;
doc.root().walk(&mut |_| n += 1);
assert_eq!(n, 2);Sourcepub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Node))
pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Node))
Mutable pre-order visit of self and every descendant.
Sourcepub fn find(&self, pred: impl FnMut(&Node) -> bool) -> Option<&Node>
pub fn find(&self, pred: impl FnMut(&Node) -> bool) -> Option<&Node>
First node (incl. self) matching pred, pre-order.
Sourcepub fn find_mut(&mut self, pred: impl FnMut(&Node) -> bool) -> Option<&mut Node>
pub fn find_mut(&mut self, pred: impl FnMut(&Node) -> bool) -> Option<&mut Node>
Mutable variant of Node::find.
Sourcepub fn find_all(&self, pred: impl FnMut(&Node) -> bool) -> Vec<&Node>
pub fn find_all(&self, pred: impl FnMut(&Node) -> bool) -> Vec<&Node>
All nodes (incl. self) matching pred, pre-order.
Sourcepub fn find_all_mut(
&mut self,
pred: &mut impl FnMut(&Node) -> bool,
) -> Vec<&mut Node>
pub fn find_all_mut( &mut self, pred: &mut impl FnMut(&Node) -> bool, ) -> Vec<&mut Node>
Mutable variant of Node::find_all. Collects matching &mut Node.
Sourcepub fn descendants(&self) -> Descendants<'_> ⓘ
pub fn descendants(&self) -> Descendants<'_> ⓘ
Lazy pre-order iterator over self and all descendants.