PreprocessRule.apply
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.
Transforms one block in the legacy rendering pipeline. You implement this callback on a PreprocessRule; you do not call it directly.
Signature
apply(text: string, renderer: RenderContext): stringParameters
| Parameter | Description |
|---|---|
text | Current block after all lower-priority legacy rules |
renderer | Current document's legacy RenderContext |
SmartRenderer supplies both values. The rule should treat text as its complete input and return a string for the next rule even when no match is found.
Returns
The source passed to the next legacy rule. After the final rule, Markdown-it renders the result and protected HTML is restored.
Call relationships
- Called by:
SmartRenderer.renderBlockToHtmlin ascending rule priority. - Usually calls: balanced source readers,
renderer.protectHtml, orrenderer.renderInline. - Does not run in: AST mode.
previous rule output -> apply(text, renderer) -> next rule input -> Markdownconst RULE: PreprocessRule = {
priority: 200,
apply: (text, _renderer) =>
text.replace(/\\draftmarker\b/g, '')
};SnapTeX still supplies the second argument. The _renderer name makes the complete callback shape visible while showing that this rule intentionally does not use the rendering context.
priority controls ordering; it does not match source. Always return the unmodified text when the rule does not apply.