Skip to content

feat(vscode): render KaTeX math in chat messages#105

Open
zeug-zz wants to merge 3 commits into
ktmage:developmentfrom
zeug-zz:feat/katex-renderer
Open

feat(vscode): render KaTeX math in chat messages#105
zeug-zz wants to merge 3 commits into
ktmage:developmentfrom
zeug-zz:feat/katex-renderer

Conversation

@zeug-zz

@zeug-zz zeug-zz commented Jun 8, 2026

Copy link
Copy Markdown

Wire marked-katex-extension into the existing marked instance used by TextPartView so $inline$ and $$display$$ math render at parse time alongside the rest of the Markdown.

What changes

  • Add katex and marked-katex-extension as runtime dependencies of the VS Code webview package.
  • Import katex/dist/katex.min.css from main.tsx (Vite-bundled) rather than from styles.css, so KaTeX styles are owned by the entry that depends on them and @import semantics stay out of the app stylesheet.
  • Switch the marked wrapper from <span> to <div> so block-level elements produced by marked (and .katex-display) produce valid HTML.
  • Loosen the webview CSP: split style-src / style-src-attr / style-src-elem and permit 'unsafe-inline' on style-src-attr so KaTeX's per-element style="height:...; vertical-align:...;" attributes are honored (stacked fraction layout).

Impact

  • 7 files changed, +73 / −21
  • Tests: 1533/1533 pass on development + this commit
  • pnpm check introduces no new warnings in the touched files
  • Bundle: index.js 842.99 kB (gzip 258.81 kB), index.css 73.77 kB (gzip 15.30 kB)
  • New runtime deps: katex, marked-katex-extension
  • No breaking changes for non-math Markdown
  • Selecting and copying rendered text still copies the visible (KaTeX) output — preserving the original LaTeX source is the job of a separate follow-up PR

@ktmage

ktmage commented Jun 9, 2026

Copy link
Copy Markdown
Owner

@zeug-zz こちらも同じく、reviewして良さそうならreviewerにいれてください!

@zeug-zz

zeug-zz commented Jun 9, 2026

Copy link
Copy Markdown
Author

@zeug-zz こちらも同じく、reviewして良さそうならreviewerにいれてください!

@ktmage yes go ahead! Feel free to self-assign as reviewer, I don't have the permissions to add you from this side.

@ktmage ktmage self-requested a review June 9, 2026 23:33
zeug-zz added 2 commits June 15, 2026 10:46
Wire marked-katex-extension into the existing Marked parser in
TextPartView so $inline$ and $$display$$ math is rendered at
parse time. Wrap the markdown output in <div> instead of <span> so
block-level elements produced by marked (and .katex-display) are
valid HTML.

- Add katex and marked-katex-extension to vscode webview deps.
- Import katex/dist/katex.min.css from main.tsx (bundled by Vite)
  rather than styles.css to keep CSS @import semantics out of the
  app stylesheet.
- Loosen the webview CSP: split style-src / style-src-attr /
  style-src-elem and permit 'unsafe-inline' on style-src-attr so
  KaTeX's per-element style="height:...; vertical-align:...;"
  attributes are honored (stacked fraction layout).
- Add scoped KaTeX rules to MessageItem.module.css: .katex sizing
  and line-height, .katex-display block layout with horizontal
  scroll, vertical-align: baseline on .katex-display > .katex to
  prevent the inline-math rule from shifting display math, and a
  direct-child p > .katex selector for inline math.
- Update TextPartView test to assert the .markdown container
  element.
@zeug-zz zeug-zz force-pushed the feat/katex-renderer branch from 264ca39 to 5e8d255 Compare June 14, 2026 22:47
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.

2 participants