Skip to content
This page is available as Markdown at /api/traversal/functions/getenclosingblock.md. For the full documentation index, see /llms.txt, or the complete corpus at /llms-full.txt.

getEnclosingBlock

getEnclosingBlock<TMatch>(snapshot, path, options): { node: TMatch; path: Path; } | undefined

Defined in: get-enclosing-block.ts:25

Walk up from a path to find the nearest enclosing block.

Returns the node at the path if it is a block, otherwise the first ancestor that is a block. Works at any depth — inside a container this returns the container-internal block, not the outer container.

With match, returns the first enclosing block that also satisfies the predicate. When match is a type predicate, the returned node narrows to that type.

mode: 'lowest' (default) returns the innermost enclosing block; the node at the path itself counts. mode: 'highest' returns the outermost ancestor that matches, falling back to the node at the path only if no ancestor does.

TMatch extends PortableTextBlock

TraversalSnapshot

Path

(node, path) => node is TMatch

"lowest" | "highest"

{ node: TMatch; path: Path; } | undefined

getEnclosingBlock(snapshot, path, options?): { node: PortableTextBlock; path: Path; } | undefined

Defined in: get-enclosing-block.ts:36

TraversalSnapshot

Path

(node, path) => boolean

"lowest" | "highest"

{ node: PortableTextBlock; path: Path; } | undefined