> For the complete documentation index, see [llms.txt](/llms.txt).
> The full corpus is at [llms-full.txt](/llms-full.txt).

# getEnclosingBlock

## Call Signature

> **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.

### Type Parameters

#### TMatch

`TMatch` *extends* `PortableTextBlock`

### Parameters

#### snapshot

`TraversalSnapshot`

#### path

`Path`

#### options

##### match

(`node`, `path`) => `node is TMatch`

##### mode?

`"lowest"` \| `"highest"`

### Returns

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

## Call Signature

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

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

### Parameters

#### snapshot

`TraversalSnapshot`

#### path

`Path`

#### options?

##### match?

(`node`, `path`) => `boolean`

##### mode?

`"lowest"` \| `"highest"`

### Returns

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