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(...), 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.
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): stringParameters
| Parameter | Description |
|---|---|
text | Untrusted or plain source text |
Returns
A string with &, <, >, ", and ' represented as HTML entities.
Call relationships
- Called by: legacy and AST rendering rules before interpolating plain text into HTML.
- Often followed by:
renderer.protectHtmlin legacy mode. - Equivalent AST context method:
context.escapeHtml.
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.