pub struct Node(/* private fields */);Expand description
A node in the document tree: an element with attributes, child content and
marks, or — when is_text — a marked text run.
Positions follow the ProseMirror model. A text node’s size is its length
in Unicode scalar values (chars — note this differs from ProseMirror’s
UTF-16 units; the DOM bridge maps between them). A non-text leaf has size
1; any other node has size content.size + 2.
Implementations§
Source§impl Node
impl Node
Sourcepub fn to_html(&self) -> String
pub fn to_html(&self) -> String
Serialize this node (and its subtree) to an HTML string.
Text and attribute values are HTML-escaped. A node type whose spec has
no to_dom is transparent — only its content is emitted (the usual
case for the document node), which is why a serialized document is a
run of its block children with no wrapper.
Source§impl Node
impl Node
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Number of direct children.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
The concatenated text of this node and its descendants.
Sourcepub fn with_marks(&self, marks: Vec<Mark>) -> Node
pub fn with_marks(&self, marks: Vec<Mark>) -> Node
Return a copy of this node with marks as its mark set.
Source§impl Node
impl Node
Sourcepub fn replace(
&self,
from: usize,
to: usize,
slice: &Slice,
schema: &Schema,
) -> Result<Node, ReplaceError>
pub fn replace( &self, from: usize, to: usize, slice: &Slice, schema: &Schema, ) -> Result<Node, ReplaceError>
Replace the range from..to with slice, returning the new root.
The document is treated as the root. Content that would violate the
schema (including illegal joins at the boundaries) is rejected with a
ReplaceError rather than silently produced.