renderer.protectHtml
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.
Stores trusted generated HTML behind a temporary token while Markdown renders surrounding text. Call it only from the legacy path when your rule has already generated trusted HTML.
Signature
renderer.protectHtml(
namespace: string,
html: string,
mode?: 'block' | 'inline'
): stringParameters
| Parameter | Description |
|---|---|
namespace | Short diagnostic token category such as badge or math |
html | Trusted HTML generated by the rule |
mode | Restoration behavior; defaults to block |
Returns
A temporary text token. Return or embed the token in transformed rule text; do not expose it to users directly.
The returned token belongs to the current block's protection manager. Do not cache it across blocks or preview updates.
Call relationships
- Called by: legacy
PreprocessRule.applycallbacks and helpers such asrenderMath. - Calls:
ProtectionManager.protect. - Resolved after: Markdown-it finishes rendering the block.
escaped/generated HTML -> protectHtml -> temporary token -> Markdown -> restored HTMLChoosing a mode
- Use
inlinefor a fragment that belongs inside a paragraph. - Use the default
blockmode for complete block-level HTML such as a table or figure.
return renderer.protectHtml(
'badge',
`<span class="badge">${escapeHtml(content)}</span>`,
'inline'
);Escape user-controlled values before interpolating them. protectHtml prevents Markdown transformation; it is not an HTML sanitizer.