feat(chat): typeset LaTeX in chat and markdown preview - #780
SpookySandwich wants to merge 2 commits into
Conversation
SDSLeon
left a comment
There was a problem hiding this comment.
Reviewed all eight changed files at 833ac07, including both rendering pipelines, sanitization/error handling, dependency resolution, styles, and tests. One Important finding: the KaTeX stylesheet does not match the renderer version and loses essential layout/sizing rules.
The shared pipeline preserves sanitization before generated markup and catches malformed equations locally. All 61 targeted tests passed (chatMathRendering, ItemMarkdownInner, ItemMarkdown, markdownPathRefRendering). A separate computed-style reproduction confirmed the version mismatch; the JSX tests do not load CSS. No unsafe trust bypass was found. GitHub reports no CI checks for this branch. Full Electron visual verification was not rerun. Nits omitted.
| "json5": "^2.2.3", | ||
| "jsonc-parser": "3.3.1", | ||
| "jsqr": "^1.4.0", | ||
| "katex": "^0.18.7", |
There was a problem hiding this comment.
[P1] Match the KaTeX stylesheet to the renderer version
The direct katex dependency supplies tailwind.css with 0.18.7 CSS, but the lockfile resolves rehype-katex to KaTeX 0.16.47 for actual rendering. In 0.18 the stylesheet renamed classes such as .base, .strut, and .sizing to prefixed classes, so the 0.16 HTML loses its positioning and script-size rules in both chat and file preview. Rendering \frac{1}{2}+x^2 with the installed renderer and applying these styles reproduces .sizing at 19.36px instead of the matching stylesheet's 13.552px, and .base becomes inline/static instead of inline-block/relative. The new tests only assert generated DOM and do not load this CSS. Align the direct KaTeX dependency with the renderer (e.g. 0.16.47), regenerate the lockfile, and verify fractions/superscripts with the actual bundled stylesheet.
Typeset math in chat and Markdown previews with a shared
remark-math-extended+ KaTeX pipeline. Both$…$/$$…$$and\(...\)/\[…\]work, including replies that mix them. KaTeX runs after sanitization; malformed formulas stay local to the equation, and inline/fenced code stays literal.Known parser tradeoffs:
$5 and $10can become one formula, and\[1\]is display math. Use\\[for a literal backslash-bracket.Validation
Before and after
Matching standalone previews of the same sample, with plain Markdown before and math rendering after.
Mixed-syntax reply in the isolated app and file preview
Chat:
File preview: