Node
This class represents a node in the tree that makes up a
ProseMirror document. So a document is an instance of Node
, with
children that are also instances of Node
.
Nodes are persistent data structures. Instead of changing them, you create new ones with the content you want. Old ones keep pointing at the old document shape. This is made cheaper by sharing structure between the old and new data as much as possible, which a tree shape like this (without back pointers) makes easy.
Do not* directly mutate the properties of a Node
object. See
the guide for more information.
§Properties
An object mapping attribute names to values. The kind of attributes allowed and required are determined by the node type.
The size of this node, as defined by the integer-based indexing scheme. For text nodes, this is the amount of characters. For other leaf nodes, it is one. For non-leaf nodes, it is the size of the content plus two (the start and end token).
Concatenates all the text nodes found in this fragment and its children.
True when this is a textblock node, a block node with inline content.
True when this is an inline node (a text node or a node that can appear among text).
True when this is an atom, i.e. when it does not have directly
editable content. This is usually the same as isLeaf
, but can
be configured with the atom
property
on a node's spec (typically used when the node is displayed as
an uneditable node view).
§Methods
Test whether replacing the range between from
and to
(by
child index) with the given replacement fragment (which defaults
to the empty fragment) would leave the node's content valid. You
can optionally pass start
and end
indices into the
replacement fragment.
Check whether this node and its descendants conform to the schema, and raise error when they do not.
Get the content match in this node at the given index.
Invoke a callback for all descendant nodes recursively between the given two positions that are relative to start of this node's content. The callback is invoked with the node, its position relative to the original node (method receiver), its parent node, and its child index. When the callback returns false for a given node, that node's children will not be recursed over. The last parameter can be used to specify a starting position to count from.
Replace the part of the document between the given positions with
the given slice. The slice must 'fit', meaning its open sides
must be able to connect to the surrounding content, and its
content nodes must be valid children for the node they are placed
into. If any of this is violated, an error of type
ReplaceError
is thrown.
Resolve the given position in the document, returning an object with information about its context.
Get all text between positions from
and to
. When
blockSeparator
is given, it will be inserted to separate text
from different block nodes. If leafText
is given, it'll be
inserted for every non-text leaf node encountered, otherwise
leafText
will be used.