abstract class markdown::Node

sys::Obj
  markdown::Node

@Js

Source

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.

addSourceSpan

Void addSourceSpan(SourceSpan? sourceSpan)

Source

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

appendChild

This appendChild(Node child)

Source

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

children

Node[] children()

Source

Get all the direct children of this node

doc

Document? doc()

Source

Get the root Document node or null if this node is mounted in a document yet

eachBetween

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

Source

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

Void eachChild(|Node| f)

Source

Invoke the callback on each direct child of this node

eachDescendant

Void eachDescendant(|Node| f)

Source

Recursively walk the descendants of this node using a depth-first search and invoke the callback on each node.

find

Node? find(Type nodeType, Bool checked := true)

Source

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.

findAll

Node[] findAll(|Node->Bool| f)

Source

Recursively find all children of this node for which the callback returns true

firstChild

Node? firstChild { private set }

Source

insertAfter

Void insertAfter(Node sibling)

Source

Inserts the sibling node after this node

insertBefore

Void insertBefore(Node sibling)

Source

Inserts the sibiling node before this node

lastChild

Node? lastChild { private set }

Source

loc

FileLoc loc()

Source

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.

make

new make()

Source

next

Node? next { private set }

Source

parent

virtual Node? parent()

Source

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

prev

Node? prev { private set }

Source

setParent

protected virtual Void setParent(Node? p)

Source

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

setSourceSpans

Void setSourceSpans(SourceSpan[] sourceSpans)

Source

Replace the current source spans with the provided list

sourceSpans

SourceSpan[] sourceSpans := SourceSpan[,] { private set }

Source

toStr

virtual override Str toStr()

Source

toStrAttributes

protected virtual Str toStrAttributes()

Source

Void unlink()

Source

Completely detach this node from the AST

walk

virtual Void walk(Visitor visitor)

Source

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