Skip to content

context.escapeHtml ​

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(...), and collect(...) are callbacks that your rule implements and SnapTeX calls.
  • renderer.name(...), context.name(...), input.name(...), and deps.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 constructs PreviewUpdateService.

Register extension declarations through SNAP_TEX_RULES in src/rules.ts. See Source API Scope for imports, value ownership, output safety, rebuilds, and testing.

Escapes plain text for direct insertion into AST-rendered HTML. Call it through the context received by an AstRenderRule; do not import or construct that context.

Signature ​

ts
context.escapeHtml(text: string): string

Returns ​

HTML-safe text. This context method uses the same implementation as escapeHtml.

Call relationships ​

  • Called by: AST rules that promise plain-text arguments.
  • Returns: direct HTML text, not a protected token.
  • Does not: render nested LaTeX.
text
plain source text -> context.escapeHtml -> safe HTML text -> rule HTML
ts
return { html: `<span>${context.escapeHtml(content)}</span>` };

See also ​

A fast structural preview, not a replacement for a full TeX compiler.