Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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.

class Node {
readonly attrs: Attrs;
readonly content: Fragment;
readonly marks: readonly Mark[];
get nodeSize(): number;
get childCount(): number;
get firstChild(): Node | null;
readonly text: string | undefined;
get textContent(): string;
get lastChild(): Node | null;
get isBlock(): boolean;
get isTextblock(): boolean;
get inlineContent(): boolean;
get isInline(): boolean;
get isText(): boolean;
get isLeaf(): boolean;
get isAtom(): boolean;
readonly type: NodeType;
 
canAppend(other: Node): boolean;
canReplace(
from: number,
to: number,
replacement?: Fragment,
start?: number,
end?: number,
): boolean;
canReplaceWith(
from: number,
to: number,
type: NodeType,
marks?: readonly Mark[],
): boolean;
check(): void;
child(index: number): Node;
childAfter(pos: number): {
node: Node | null;
index: number;
offset: number;
}
;
childBefore(pos: number): {
node: Node | null;
index: number;
offset: number;
}
;
contentMatchAt(index: number): ContentMatch;
copy(content?: Fragment | null): Node;
cut(from: number, to?: number): Node;
descendants(f: (
node: Node,
pos: number,
parent: Node | null,
index: number,
) => void | boolean
): void;
eq(other: Node): boolean;
forEach(f: (
node: Node,
offset: number,
index: number,
) => void
): void;
hasMarkup(
type: NodeType,
attrs?: Attrs | null,
marks?: readonly Mark[],
): boolean;
mark(marks: readonly Mark[]): Node;
maybeChild(index: number): Node | null;
nodeAt(pos: number): Node | null;
nodesBetween(
from: number,
to: number,
f: (
node: Node,
pos: number,
parent: Node | null,
index: number,
) => void | boolean
,
startPos?: number,
): void;
rangeHasMark(
from: number,
to: number,
type: Mark | MarkType,
): boolean;
replace(
from: number,
to: number,
slice: Slice,
): Node;
resolve(pos: number): ResolvedPos;
sameMarkup(other: Node): boolean;
slice(
from: number,
to?: number,
includeParents?: boolean,
): Slice;
textBetween(
from: number,
to: number,
blockSeparator?: string | null,
leafText?: null | string | ((leafNode: Node) => string),
): string;
toJSON(): any;
toString(): string;
 
static fromJSON(schema: Schema, json: any): Node;
}

§Properties

§
attrs: Attrs
[src]

An object mapping attribute names to values. The kind of attributes allowed and required are determined by the node type.

§
content: Fragment
[src]

A container holding the node's children.

§
marks: readonly Mark[]
[src]

The marks (things like whether it is emphasized or part of a link) applied to this node.

§
nodeSize: number readonly
[src]

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).

§
childCount: number readonly
[src]

The number of children that the node has.

§
firstChild: Node | null readonly
[src]

Returns this node's first child, or null if there are no children.

§
text: string | undefined
[src]

For text nodes, this contains the node's text content.

§
textContent: string readonly
[src]

Concatenates all the text nodes found in this fragment and its children.

§
lastChild: Node | null readonly
[src]

Returns this node's last child, or null if there are no children.

§
isBlock: boolean readonly
[src]

True when this is a block (non-inline node)

§
isTextblock: boolean readonly
[src]

True when this is a textblock node, a block node with inline content.

§
inlineContent: boolean readonly
[src]

True when this node allows inline content.

§
isInline: boolean readonly
[src]

True when this is an inline node (a text node or a node that can appear among text).

§
isText: boolean readonly
[src]

True when this is a text node.

§
isLeaf: boolean readonly
[src]

True when this is a leaf node.

§
isAtom: boolean readonly
[src]

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).

§

The type of node that this is.

§Methods

§
canAppend(other: Node): boolean
[src]

Test whether the given node's content could be appended to this node. If that node is empty, this will only return true if there is at least one node type that can appear in both nodes (to avoid merging completely incompatible nodes).

§
canReplace(from: number, to: number, replacement?: Fragment, start?: number, end?: number): boolean
[src]

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.

§
canReplaceWith(from: number, to: number, type: NodeType, marks?: readonly Mark[]): boolean
[src]

Test whether replacing the range from to to (by index) with a node of the given type would leave the node's content valid.

§
check(): void
[src]

Check whether this node and its descendants conform to the schema, and raise error when they do not.

§
child(index: number): Node
[src]

Get the child node at the given index. Raises an error when the index is out of range.

§
childAfter(pos: number): {
node: Node | null;
index: number;
offset: number;
}
[src]

Find the (direct) child node after the given offset, if any, and return it along with its index and offset relative to this node.

§
childBefore(pos: number): {
node: Node | null;
index: number;
offset: number;
}
[src]

Find the (direct) child node before the given offset, if any, and return it along with its index and offset relative to this node.

§
contentMatchAt(index: number): ContentMatch
[src]

Get the content match in this node at the given index.

§
copy(content?: Fragment | null): Node
[src]

Create a new node with the same markup as this node, containing the given content (or empty, if no content is given).

§
cut(from: number, to?: number): Node
[src]

Create a copy of this node with only the content between the given positions. If to is not given, it defaults to the end of the node.

§
descendants(f: (node: Node, pos: number, parent: Node | null, index: number) => void | boolean): void
[src]

Call the given callback for every descendant node. Doesn't descend into a node when the callback returns false.

§
eq(other: Node): boolean
[src]

Test whether two nodes represent the same piece of document.

§
forEach(f: (node: Node, offset: number, index: number) => void): void
[src]

Call f for every child node, passing the node, its offset into this parent node, and its index.

§
hasMarkup(type: NodeType, attrs?: Attrs | null, marks?: readonly Mark[]): boolean
[src]

Check whether this node's markup correspond to the given type, attributes, and marks.

§
mark(marks: readonly Mark[]): Node
[src]

Create a copy of this node, with the given set of marks instead of the node's own marks.

§
maybeChild(index: number): Node | null
[src]

Get the child node at the given index, if it exists.

§
nodeAt(pos: number): Node | null
[src]

Find the node directly after the given position.

§
nodesBetween(from: number, to: number, f: (node: Node, pos: number, parent: Node | null, index: number) => void | boolean, startPos?: number): void
[src]

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.

§
rangeHasMark(from: number, to: number, type: Mark | MarkType): boolean
[src]

Test whether a given mark or mark type occurs in this document between the two given positions.

§
replace(from: number, to: number, slice: Slice): Node
[src]

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(pos: number): ResolvedPos
[src]

Resolve the given position in the document, returning an object with information about its context.

§
sameMarkup(other: Node): boolean
[src]

Compare the markup (type, attributes, and marks) of this node to those of another. Returns true if both have the same markup.

§
slice(from: number, to?: number, includeParents?: boolean): Slice
[src]

Cut out the part of the document between the given positions, and return it as a Slice object.

§
textBetween(from: number, to: number, blockSeparator?: string | null, leafText?: null | string | ((leafNode: Node) => string)): string
[src]

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.

§
toJSON(): any
[src]

Return a JSON-serializeable representation of this node.

§
toString(): string
[src]

Return a string representation of this node for debugging purposes.

§Static Methods

§
fromJSON(schema: Schema, json: any): Node
[src]

Deserialize a node from its JSON representation.