Add LaTeX math rendering to MarkdownPreview (#441)#442
Merged
Conversation
Render LaTeX in the shared MarkdownPreview component, which backs both the timeline message renderer and the markdown file preview. Math is parsed with remark-math and rendered with rehype-katex (KaTeX CSS imported); for the allowHtml file-preview path, rehype-katex runs after rehype-sanitize so the language-math wrappers the default schema preserves are rendered without re-sanitizing KaTeX's own (trust:false) output. GitHub-style delimiters: $x$ inline and $$x$$ block. Single-dollar math is on, so a literal $ in prose is escaped with \$. Also widen isGutterUtilityPath to accept the [EventTarget?] shape that @types/node's web-globals give Event.composedPath(), clearing a pre-existing typecheck failure. Tests: inline/display/escaped-dollar/invalid-TeX and the allowHtml math+sanitize path; added a "math (LaTeX)" story row. Full @bb/app suite and build green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #441.
What
Adds LaTeX math rendering to the shared
MarkdownPreviewcomponent, which backs both surfaces in the issue — the timeline message renderer (assistant + user messages) and the markdown file preview.remark-mathparses$…$/$$…$$;rehype-katexrenders with KaTeX (stylesheet imported, fonts bundled by Vite).allowHtmlfile-preview path,rehype-katexruns afterrehype-sanitize: the default schema already keeps thelanguage-mathclass on<code>, so the math wrappers survive sanitization and KaTeX (which runs withtrust: falseand self-escapes its TeX input) emits its output without being re-sanitized.currentColor, so math tracks--foregroundacross custom palettes.Delimiters
GitHub-style (per design decision):
$x$inline and$$x$$block both render. Known trade-off — a line with two unescaped$(e.g.$5 to $10,$HOME and $PATH) parses the span between them as math; authors escape a literal dollar with\$. Documented in a code comment; flipping to$$-only later is a one-line change (singleDollarTextMath: false).Also
Widened
isGutterUtilityPathto accept the[EventTarget?]shape that@types/node's web-globals giveEvent.composedPath(), clearing a pre-existing typecheck failure inPierreLineSelectionActions.tsx(unrelated to math, but it was blocking a cleantsc).Tests run
turbo run typecheck --filter=@bb/app— 0 errors.turbo run test --filter=@bb/app— 1115 passing (5 new math tests: inline, display, escaped-dollar literal, allowHtml math+sanitize, invalid-TeX containment).turbo run build --filter=@bb/app— green; KaTeX CSS + fonts bundled.Risks
\$and documented.A 10-agent adversarial review verified no XSS through the math path and no missed render paths.
🤖 Generated with Claude Code