- Index
- »
- fan.markdown
- »
- Node
Node
@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.
Insert the child node as the last child node of this node
Get the file location for this node from the original parsed source
The parent node or null if this is the root of the AST
Invoke the callback on each direct child of this node
Get nodes between start (exclusive) and end (exclusive) by iterating siblings of the start node
Replace the current source spans with the provided list
Recursively find all children of this node for which the callback returns true
Inserts the sibling node after this node
Inserts the sibiling node before this node
Add a source span to the end of the list
Completely detach this node from the AST
Get all the direct children of this node
Recursively try to find a node with the given type within the children of this node
Recursively walk the descendants of this node using a depth-first search and invoke the callback on each node
Get the root Document node or null if this node is mounted in a document yet
Used by sub-classes to set or clear this node's parent
Walk the AST using the given visitor
Void addSourceSpan(SourceSpan? sourceSpan)
Add a source span to the end of the list. If it is null, this is a no-op
This appendChild(Node child)
Insert the child node as the last child node of this node.
Node[] children()
Get all the direct children of this node
Document? doc()
Get the root Document node or null if this node is mounted in a document yet
static Void eachBetween(Node start, Node? end, |Node| f)
Get nodes between start (exclusive) and end (exclusive) by iterating siblings of the start node.
// A -> B -> C-> D-> E
|->B1 |-> D1
|->B2
Node.eachBetween(A, D, f) => f(B), f(C)
Node.eachBetween(B, null, f) => f(C), f(D), f(E)
Void eachChild(|Node| f)
Invoke the callback on each direct child of this node
Void eachDescendant(|Node| f)
Recursively walk the descendants of this node using a depth-first search and invoke the callback on each node.
Node? find(Type nodeType, Bool checked)
Recursively try to find a node with the given type within the children of this node. If checked, throw an error if the node could not be found; otherwise return null.
Node[] findAll(|Node->Bool| f)
Recursively find all children of this node for which the callback returns true
Node? : firstChild
Void insertAfter(Node sibling)
Inserts the sibling node after this node
Void insertBefore(Node sibling)
Inserts the sibiling node before this node
Node? : lastChild
virtual FileLoc loc()
Get the file location for this node from the original parsed source. If the location is not known or source spans were not enabled during parsing, then return FileLoc.unknown.
new make()
Node? : next
virtual Node? parent()
The parent node or null if this is the root of the AST
Node? : prev
virtual Void setParent(Node? p)
Used by sub-classes to set or clear this node's parent
Void setSourceSpans(SourceSpan[] sourceSpans)
Replace the current source spans with the provided list
SourceSpan[] : sourceSpans
virtual Str toStr()
virtual Str toStrAttributes()
Void unlink()
Completely detach this node from the AST
virtual Void walk(Visitor visitor)
Walk the AST using the given visitor. By default, we use reflection to call visitor.visit${this.typeof.name}