Skip to content

v0.3.0

Choose a tag to compare

@bertrandgressier bertrandgressier released this 13 Sep 07:36
· 8 commits to main since this release
6d998d7

Summary

Inline math joins the component output mode, using the new inlineComponent node type added upstream in @tanstack/markdown 0.0.15. Full math rendering (block + inline) now works without allowHtml, with a serialization-clean AST.

Changes

  • Inline component outputmathInlineExtension({ output: 'component' }) emits inlineComponent nodes ({ name: 'math', tagName: 'MathInline', properties: { tex } }) instead of pre-rendered inlineHtml. The extension's renderHtml hook renders them in the HTML renderer (KaTeX inline mode, no allowHtml), and React consumers map them via components: { MathInline }.
  • New MathInline React component — exported from tanstack-markdown-math/react; renders tex via KaTeX in inline mode (displayMode: false by default).
  • New inlineTagName option — customizes the inline component tag name (default 'MathInline'). tagName remains block-only.
  • output: 'component' on mathExtension() now applies to both block and inline math — previously inline math always stayed inlineHtml.
  • Trimmed TeX payloads — inline component properties.tex is trimmed, keeping the AST clean when allowSpaces captures edge whitespace.
  • LRU render cache — every extension instance wraps its renderer in a transparent cache keyed by (tex, displayMode) (max 1000 entries by default). Repeated formulas and streaming re-parses skip redundant KaTeX calls: on a dense 262 KB medical corpus (~1156 formulas, 37% repeats), parse+render drops from ~44 ms to ~11 ms (html mode) and ~49 ms to ~8 ms (component mode). Custom render functions are cached too (assumed pure); thrown errors are never cached.
  • New cache optioncache: false disables the render cache (for impure custom renderers); cache: <number> sets a custom entry limit.
  • Memoized React componentsMathBlock and MathInline are wrapped in React.memo keyed on (tex, displayMode), so React re-renders no longer re-run KaTeX for unchanged formulas.
  • 33 new integration tests (TDD, written before implementation) covering parsing in all inline containers, real-world formula extraction from a dense medical corpus (chemistry brackets, Greek letters, French decimal commas, multi-math sentences, prose/money dollar false positives, code protection, protectMath round-trip), HTML rendering without allowHtml, custom renderers, JSON round-trips, React components mapping, SSR, streaming behavior, and render-cache semantics.

Impact on consumers

No action required for existing code. The default output mode ('html') is unchanged and fully backward compatible.

  • If you use mathExtension({ output: 'component' }) (introduced in 0.2.0): inline math now also emits inlineComponent nodes instead of inlineHtml. Map MathInline in your components option (or your own component reading props.tex) to render it; the HTML renderer needs nothing.
  • Inline output: 'component' requires @tanstack/markdown >= 0.0.15. The default 'html' mode still works with >= 0.0.13.
  • If you pass a custom render function, its results are now cached (it is assumed pure). If your renderer relies on side effects or produces non-deterministic output, set cache: false on the extension options.