Skip to main content

Node

Struct Node 

Source
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

Source

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

Source

pub fn to_json(&self) -> Value

Serialize this node (and its subtree) to JSON.

Source§

impl Node

Source

pub fn node_type(&self) -> &NodeType

This node’s type.

Source

pub fn attrs(&self) -> &Attrs

This node’s attributes.

Source

pub fn content(&self) -> &Fragment

This node’s child fragment (empty for text and leaf nodes).

Source

pub fn marks(&self) -> &[Mark]

The marks applied to this node.

Source

pub fn text(&self) -> Option<&str>

The text of a text node, or None for element nodes.

Source

pub fn is_text(&self) -> bool

Whether this is a text node.

Source

pub fn is_leaf(&self) -> bool

Whether this node is a leaf (no content).

Source

pub fn is_inline(&self) -> bool

Whether this node is inline.

Source

pub fn is_block(&self) -> bool

Whether this node is a block.

Source

pub fn child_count(&self) -> usize

Number of direct children.

Source

pub fn child(&self, i: usize) -> &Node

Borrow the child at index i.

§Panics

Panics if i >= child_count().

Source

pub fn node_size(&self) -> usize

The number of positions this node occupies in its parent.

Source

pub fn text_content(&self) -> String

The concatenated text of this node and its descendants.

Source

pub fn with_marks(&self, marks: Vec<Mark>) -> Node

Return a copy of this node with marks as its mark set.

Source

pub fn node_at(&self, pos: usize) -> Option<Node>

The node that begins at absolute position pos within this node’s subtree (descending into children), or None if pos does not land exactly on a node boundary.

Source§

impl Node

Source

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.

Source

pub fn slice(&self, from: usize, to: usize) -> Result<Slice, DocError>

Extract the content between from and to as a Slice, recording how deeply each end is open so it can be re-inserted faithfully.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Node

Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.