v0.3.0
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 output —
mathInlineExtension({ output: 'component' })emitsinlineComponentnodes ({ name: 'math', tagName: 'MathInline', properties: { tex } }) instead of pre-renderedinlineHtml. The extension'srenderHtmlhook renders them in the HTML renderer (KaTeX inline mode, noallowHtml), and React consumers map them viacomponents: { MathInline }. - New
MathInlineReact component — exported fromtanstack-markdown-math/react; renderstexvia KaTeX in inline mode (displayMode: falseby default). - New
inlineTagNameoption — customizes the inline component tag name (default'MathInline').tagNameremains block-only. output: 'component'onmathExtension()now applies to both block and inline math — previously inline math always stayedinlineHtml.- Trimmed TeX payloads — inline component
properties.texis trimmed, keeping the AST clean whenallowSpacescaptures 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). Customrenderfunctions are cached too (assumed pure); thrown errors are never cached. - New
cacheoption —cache: falsedisables the render cache (for impure custom renderers);cache: <number>sets a custom entry limit. - Memoized React components —
MathBlockandMathInlineare wrapped inReact.memokeyed 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,
protectMathround-trip), HTML rendering withoutallowHtml, custom renderers, JSON round-trips, Reactcomponentsmapping, 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 emitsinlineComponentnodes instead ofinlineHtml. MapMathInlinein yourcomponentsoption (or your own component readingprops.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
renderfunction, its results are now cached (it is assumed pure). If your renderer relies on side effects or produces non-deterministic output, setcache: falseon the extension options.