Trilium Frontend API
    Preparing search index...

    Interface SyntaxNode

    A syntax node provides an immutable pointer to a given node in a tree. When iterating over large amounts of nodes, you may want to use a mutable cursor instead, which is more efficient.

    interface SyntaxNode {
        firstChild: SyntaxNode;
        from: number;
        lastChild: SyntaxNode;
        name: string;
        nextSibling: SyntaxNode;
        node: SyntaxNode;
        parent: SyntaxNode;
        prevSibling: SyntaxNode;
        to: number;
        tree: Tree;
        type: NodeType;
        childAfter(pos: number): SyntaxNode;
        childBefore(pos: number): SyntaxNode;
        cursor(mode?: IterMode): TreeCursor;
        enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): SyntaxNode;
        enterUnfinishedNodesBefore(pos: number): SyntaxNode;
        getChild(
            type: string | number,
            before?: string | number,
            after?: string | number,
        ): SyntaxNode;
        getChildren(
            type: string | number,
            before?: string | number,
            after?: string | number,
        ): SyntaxNode[];
        matchContext(context: readonly string[]): boolean;
        prop<T>(prop: NodeProp<T>): T;
        resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode;
        resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode;
        toTree(): Tree;
    }

    Hierarchy (View Summary)

    Index

    Properties

    firstChild: SyntaxNode

    The first child, if the node has children.

    from: number

    The start position of the node.

    lastChild: SyntaxNode

    The node's last child, if available.

    name: string

    The name of the node (.type.name).

    nextSibling: SyntaxNode

    This node's next sibling, if any.

    Retrieve a stable syntax node at this position.

    parent: SyntaxNode

    The node's parent node, if any.

    prevSibling: SyntaxNode

    This node's previous sibling.

    to: number

    The end position of the node.

    tree: Tree

    Get the tree that represents the current node, if any. Will return null when the node is in a tree buffer.

    type: NodeType

    The type of the node.

    Methods

    • The first child that ends after pos.

      Parameters

      • pos: number

      Returns SyntaxNode

    • The last child that starts before pos.

      Parameters

      • pos: number

      Returns SyntaxNode

    • Enter the child at the given position. If side is -1 the child may end at that position, when 1 it may start there.

      This will by default enter overlaid mounted trees. You can set overlays to false to disable that.

      Similarly, when buffers is false this will not enter buffers, only nodes (which is mostly useful when looking for props, which cannot exist on buffer-allocated nodes).

      Parameters

      • pos: number
      • side: -1 | 0 | 1
      • Optionalmode: IterMode

      Returns SyntaxNode

    • Move the position to the innermost node before pos that looks like it is unfinished (meaning it ends in an error node or has a child ending in an error node right at its end).

      Parameters

      • pos: number

      Returns SyntaxNode

    • Get the first child of the given type (which may be a node name or a group name). If before is non-null, only return children that occur somewhere after a node with that name or group. If after is non-null, only return children that occur somewhere before a node with that name or group.

      Parameters

      • type: string | number
      • Optionalbefore: string | number
      • Optionalafter: string | number

      Returns SyntaxNode

    • Like getChild, but return all matching children, not just the first.

      Parameters

      • type: string | number
      • Optionalbefore: string | number
      • Optionalafter: string | number

      Returns SyntaxNode[]

    • Test whether the node matches a given context—a sequence of direct parent nodes. Empty strings in the context array act as wildcards, other strings must match the ancestor node's name.

      Parameters

      • context: readonly string[]

      Returns boolean

    • Read the given node prop from this node.

      Type Parameters

      • T

      Parameters

      Returns T

    • Find the node around, before (if side is -1), or after (side is 1) the given position. Will look in parent nodes if the position is outside this node.

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1

      Returns SyntaxNode

    • Similar to resolve, but enter overlaid nodes.

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1

      Returns SyntaxNode

    • Get a tree for this node. Will allocate one if it points into a buffer.

      Returns Tree