Skip to content

Commit 8425a9d

Browse files
committed
feat: add LaTeX math equation rendering in chat window (#4258)
- Add KaTeX dependencies for LaTeX rendering - Integrate remark-math and rehype-katex plugins in MarkdownBlock - Add KaTeX CSS styling for proper equation display - Update CSP to allow KaTeX font loading with data: URLs - Configure Vite to handle KaTeX font assets - Update .vscodeignore to include KaTeX fonts in extension bundle Users can now write LaTeX equations using standard syntax: - Inline math: = mc^2$ - Display math: 95668\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}95668 Fixes #4258
1 parent 530c5c4 commit 8425a9d

File tree

7 files changed

+207
-4
lines changed

7 files changed

+207
-4
lines changed

pnpm-lock.yaml

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.vscodeignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
!webview-ui/build/assets/*.js
2020
!webview-ui/build/assets/*.ttf
2121
!webview-ui/build/assets/*.css
22+
!webview-ui/build/assets/fonts/*.woff
23+
!webview-ui/build/assets/fonts/*.woff2
24+
!webview-ui/build/assets/fonts/*.ttf
2225

2326
# Include default themes JSON files used in getTheme
2427
!integrations/theme/default-themes/**

src/core/webview/ClineProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ export class ClineProvider
670670

671671
const csp = [
672672
"default-src 'none'",
673-
`font-src ${webview.cspSource}`,
673+
`font-src ${webview.cspSource} data:`,
674674
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
675675
`img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:`,
676676
`media-src ${webview.cspSource}`,
@@ -757,7 +757,7 @@ export class ClineProvider
757757
<meta charset="utf-8">
758758
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
759759
<meta name="theme-color" content="#000000">
760-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;">
760+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;">
761761
<link rel="stylesheet" type="text/css" href="${stylesUri}">
762762
<link href="${codiconsUri}" rel="stylesheet" />
763763
<script nonce="${nonce}">

webview-ui/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"fzf": "^0.5.2",
4545
"i18next": "^25.0.0",
4646
"i18next-http-backend": "^3.0.2",
47+
"katex": "^0.16.11",
4748
"knuth-shuffle-seeded": "^1.0.6",
4849
"lru-cache": "^11.1.0",
4950
"lucide-react": "^0.513.0",
@@ -59,7 +60,9 @@
5960
"react-use": "^17.5.1",
6061
"react-virtuoso": "^4.7.13",
6162
"rehype-highlight": "^7.0.0",
63+
"rehype-katex": "^7.0.1",
6264
"remark-gfm": "^4.0.1",
65+
"remark-math": "^6.0.0",
6366
"remove-markdown": "^0.6.0",
6467
"shell-quote": "^1.8.2",
6568
"shiki": "^3.2.1",
@@ -82,6 +85,7 @@
8285
"@testing-library/react": "^16.2.0",
8386
"@testing-library/user-event": "^14.6.1",
8487
"@types/jest": "^29.0.0",
88+
"@types/katex": "^0.16.7",
8589
"@types/node": "20.x",
8690
"@types/react": "^18.3.23",
8791
"@types/react-dom": "^18.3.5",

0 commit comments

Comments
 (0)