Skip to content

feat!: adopt @tanstack/markdown 1.0 inlineParser API (v1.0.0) - #10

Merged
bertrandgressier merged 1 commit into
mainfrom
feat/v1
Oct 4, 2026
Merged

bertrandgressier merged 1 commit into
mainfrom
feat/v1

Conversation

@bertrandgressier

Copy link
Copy Markdown
Owner

Summary

Rewrite of the inline math pipeline on the new @tanstack/markdown 1.0 inlineParser API ($ marker, pandoc-style rules). Deletes the protectMath/PUA-substitution workaround machinery (~200 lines), shares one render path between html mode and React, hardens the block extension, and adds 25 tests.

Fixed by the rewrite (verified)

  • \$a\$ no longer renders as math (escaped $ handled by the parser, before emphasis/escapes)
  • $5-$10 range no longer split into math (pandoc rule: closing $ not followed by a digit)
  • $a*b*c$, $x_{i}*y_{j}$, $\{a\}\\ b$ work without protectMath — raw source is seen before emphasis handling
  • $a \$ b$ is now valid math (escaped $ inside body)
  • 4-space indented $$ no longer stolen as math (was ^\s*\$\$ → ^ {0,3}\$\$)
  • AST no longer mutated in place (safe double-parse for cached documents)

New

  • unclosedBlock: false option: unclosed $$ stays literal text instead of swallowing the document
  • Error output: single shared renderer, English text, neutral classes katex-error-badge / katex-error-box
  • TeX trimmed consistently in both output modes
  • Test suite 88 → 113 (escaping, currency, no-mutation, prefix-sweep streaming, pathological linearity)

Breaking changes — how to migrate

  1. Peer minimum raised to @tanstack/markdown >= 1.0.0 → pnpm add @tanstack/markdown@^1 tanstack-markdown-math@^1 (or npm/yarn equivalent). Stay on tanstack-markdown-math@0.x to keep markdown 0.0.x.
  2. Heading slugs change when headings contain inline math → regenerate stored heading anchors, TOC entries and deep links for headings containing $...$.
  3. Default error output is now English text with neutral CSS classes → update CSS targeting the old Tailwind classes / French strings, or pass a custom render option.
  4. protectMath / restoreMathChars deprecated (still exported) → remove protectMath(content) calls before parsing; already-protected content keeps working.

Validation

typecheck ✅ · 113/113 tests ✅ · build ✅ · behavioral smoke suite on built dist ✅ (escaped $, currency, unprotected TeX, no-mutation re-parse)

Replace the inline text-walker with an inlineParser ('$' marker) using
pandoc-style rules, simplify the default renderer (shared with React),
harden the block extension (indent limit, unclosedBlock option) and
trim TeX consistently in both output modes.

BREAKING CHANGE: peer dependency minimum raised to @tanstack/markdown 1.0.0.
How to migrate: run `pnpm add @tanstack/markdown@^1 tanstack-markdown-math@^1`
(or the npm/yarn equivalent).

BREAKING CHANGE: heading slugs change when headings contain inline math.
How to migrate: regenerate any stored heading anchors, table-of-contents
entries and deep links for headings that contain `$...$`.

BREAKING CHANGE: default error output now uses English text and neutral CSS
classes (katex-error-badge / katex-error-box).
How to migrate: replace styling that targeted the old Tailwind classes or
French strings with CSS for `katex-error-badge` / `katex-error-box`, or pass
a custom `render` option to keep your previous markup.

BREAKING CHANGE: protectMath and restoreMathChars are deprecated.
How to migrate: remove protectMath(content) calls before parsing; math with
`_`, `*` and `\` works without it. Both functions stay exported for
already-protected content.
@bertrandgressier
bertrandgressier merged commit a7f8538 into main Oct 4, 2026
1 check passed
@bertrandgressier
bertrandgressier deleted the feat/v1 branch October 4, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant