Skip to content

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(...), 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.

Transforms one block in the legacy rendering pipeline. You implement this callback on a PreprocessRule; you do not call it directly.

Signature ​

ts
apply(text: string, renderer: RenderContext): string

Parameters ​

ParameterDescription
textCurrent block after all lower-priority legacy rules
rendererCurrent 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 ​

text
previous rule output -> apply(text, renderer) -> next rule input -> Markdown
ts
const 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.

See also ​

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