Repository navigation
fix: preserve currency formatting alongside inline math - #976
Conversation
|
Reviewed. #975 reproduces on What I checked:
Merged locally with current Heads-up: #972 also edits both Generated by Claude Code |
# Conflicts: # lib/markdown.ts
|
#972 landed, so I merged
Generated by Claude Code |
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Dollar amounts such as
$20/moand$6currently become the opening and closing delimiters of one inline-math token. That can consume a bold heading's closing markers and render the following prose as math. This change keeps those prices and Markdown formatting readable while retaining single-dollar equations.Closes #975.
Related: #135, which proposed disabling single-dollar math entirely.
Changes
remark-mathtokenizer and reject numeric single-dollar candidates when the closing dollar precedes another digit or the content has mismatched whitespace padding. Rejecting the token lets ordinary Markdown parsing recover emphasis and links.Example
The heading now stays bold, the prices remain literal, and the description retains its spaces.
$x$,$2 + 2 = 4$,$20$, balanced padding, multiline math, and$$...$$remain supported.Validation
npm run lint— passed.npx tsc --noEmit— passed.npm test— 1,314 tests passed, including the seven added regressions.npm run build— passed.E2E_SERVER_MODE=start npm run test:e2e— passed at desktop and mobile viewport sizes.npm run lintandnpm run build— passed.git diff --check— passed.Run locally on macOS arm64 / Node 26.10.0 with isolated Pi test data. Browser checks used Chromium; physical iPhone testing was not part of this validation.
Scope and tradeoff
This is a rendering-only change with no dependency, authentication, configuration, or stored-message changes. The existing tokenizer/resolver and HTML/URL sanitization remain in use.
Dollar-delimited prose and math are inherently ambiguous. Numeric formulas with one-sided whitespace padding (such as
$2 + 2 $) or a digit immediately after the closing dollar (such as$2$3) are treated as literal text by this heuristic; balanced delimiters or$$...$$avoid that ambiguity. Non-numeric single-dollar formulas retain the previous behavior. The wrapper depends on the upstreammathTexttokenizer shape, which the rendering regressions exercise.