PreviewUpdateService.renderBlockByIndex
How to read this API
These are TypeScript APIs compiled into SnapTeX; a .tex project cannot load them at runtime.
function name(...)is a helper that your rule imports and calls.apply(...),render(...),extract(...), andcollect(...)are callbacks that your rule implements and SnapTeX calls.renderer.name(...),context.name(...),input.name(...), anddeps.name(...)are methods SnapTeX supplies to callbacks; do not import or construct them.service.name(...)is an instance method called after your host or test constructsPreviewUpdateService.
Register extension declarations through SNAP_TEX_RULES in src/rules.ts. See Source API Scope for imports, value ownership, output safety, rebuilds, and testing.
Renders one previously parsed block for lazy or virtualized preview mounting. Call it only after render(..., { deferFullHtml: true }) has established the current block map.
Signature
ts
service.renderBlockByIndex(
index: number
): Promise<{ hash: string; html?: string } | undefined>Parameters
| Parameter | Description |
|---|---|
index | Zero-based block index from the latest render payload |
Returns
The block metadata and HTML when the index exists, otherwise undefined. The service automatically selects synchronous legacy rendering or asynchronous AST rendering according to its current backend.
Call relationships
- Requires: a preceding
rendercall to populate document and renderer state. - Calls:
SmartRenderer.renderBlockByIndexorrenderBlockByIndexAsync. - Used by: viewport virtualization and lazy-render tests.
ts
await service.render(uri, source, { deferFullHtml: true });
const block = await service.renderBlockByIndex(0);
assert.match(block?.html ?? '', /First paragraph/);