context.sourceContent
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.
Returns the source span covered by a list of AST nodes. Use it to recover one contiguous source fragment; use renderChildren when the goal is HTML.
Signature
ts
context.sourceContent(nodes: readonly SnaptexAstNode[]): stringReturns
The exact current-block substring from the earliest node start to the latest node end when ranges exist; otherwise reconstructed node text.
Call relationships
- Uses: the combined AST node range and current block source.
- Called by: rules that need one contiguous source fragment for several nodes.
- Does not: render or escape the result.
ts
const source = context.sourceContent(input.node.content ?? []);Use renderChildren when the goal is HTML rather than source recovery.