type

Node

src @Js
abstract class Node : Obj

Base class for all CommonMark AST nodes.

The CommonMark AST is a tree of nodes where each node can have any number of children and one parent - except the root node which has no parent.

constructors

fields

methods

addSourceSpan

Add a source span to the end of the list.

appendChild

Insert the child node as the last child node of this node.

children

Get all the children of the given parent node

eachBetween

Get nodes between start (exclusive) and end (exclusive)

find

Recursively try to find a node with the given type within the children of the specified node.

insertAfter

Inserts the sibling node after this node

insertBefore

Inserts the sibiling node before this node

parent

The parent node or null if this is the root of the AST

setParent

Used by sub-classes to set or clear this node's parent

setSourceSpans

Replace the current source spans with the provided list

toStr
toStrAttributes
tryFind

Recursively try to find a node with the given type within the children of the specified node.

unlink

Completely detach this node from the AST

walk

Walk the AST using the given visitor.

Slot Details

addSourceSpan

src Void addSourceSpan(SourceSpan? sourceSpan)

Add a source span to the end of the list. If it is null, this is a no-op

appendChild

src This appendChild(Node child)

Insert the child node as the last child node of this node.

children

src static Node[] children(Node parent)

Get all the children of the given parent node

eachBetween

src static Void eachBetween(Node start, Node end, |Node| f)

Get nodes between start (exclusive) and end (exclusive)

find

src static Node find(Node parent, Type nodeType)

Recursively try to find a node with the given type within the children of the specified node. Throw if node could not be found

firstChild

src Node? firstChild { private set }

insertAfter

src Void insertAfter(Node sibling)

Inserts the sibling node after this node

insertBefore

src Void insertBefore(Node sibling)

Inserts the sibiling node before this node

lastChild

src Node? lastChild { private set }

make

src new make()

next

src Node? next { private set }

parent

src virtual Node? parent()

The parent node or null if this is the root of the AST

prev

src Node? prev { private set }

setParent

src protected virtual Void setParent(Node? p)

Used by sub-classes to set or clear this node's parent

setSourceSpans

src Void setSourceSpans(SourceSpan[] sourceSpans)

Replace the current source spans with the provided list

sourceSpans

src SourceSpan[]? sourceSpans := null { private set }

toStr

src virtual override Str toStr()

toStrAttributes

src protected virtual Str toStrAttributes()

tryFind

src static Node? tryFind(Node parent, Type nodeType)

Recursively try to find a node with the given type within the children of the specified node.

src Void unlink()

Completely detach this node from the AST

walk

src virtual Void walk(Visitor visitor)

Walk the AST using the given visitor. By default, we use reflection to call visitor.visit${this.typeof.name}