Skip to content

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 insertion into HTML content. Use it immediately before interpolating source-controlled plain text into generated HTML; it does not render LaTeX.

Signature ​

ts
function escapeHtml(text: string): string

Parameters ​

ParameterDescription
textUntrusted or plain source text

Returns ​

A string with &, <, >, ", and ' represented as HTML entities.

Call relationships ​

ts
const html = `<span>${escapeHtml(userText)}</span>`;

This function escapes element content. Use the repository's attribute-specific helpers for URLs or HTML attributes rather than assuming content escaping validates them.

See also ​

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