Skip to content

Commit eb6e481

Browse files
feat: LaTeX formatting (RooCodeInc#3242)
* initial * initial * restored package-lock.json * restored comment * One line * prettier * do not throw on error * escape backslashes in system notification * better prompt * reduce prompt size * prettier --------- Co-authored-by: canvrno <[email protected]>
1 parent 61d2f42 commit eb6e481

File tree

10 files changed

+1215
-1638
lines changed

10 files changed

+1215
-1638
lines changed

.changeset/curly-guests-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
Full support for LaTeX rendering

.vscodeignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ docs/**
3737
!node_modules/@vscode/codicons/dist/codicon.css
3838
!node_modules/@vscode/codicons/dist/codicon.ttf
3939

40+
# Include KaTeX CSS and fonts for LaTeX rendering
41+
!webview-ui/node_modules/katex/dist/katex.min.css
42+
!webview-ui/node_modules/katex/dist/fonts/**
43+
4044
# Include default themes JSON files used in getTheme
4145
!src/integrations/theme/default-themes/**
4246

4347
# Include icons
44-
!assets/icons/**
48+
!assets/icons/**

src/core/prompts/system.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ CAPABILITIES
573573
: ""
574574
}
575575
- You have access to MCP servers that may provide additional tools and resources. Each server may provide different capabilities that you can use to accomplish tasks more effectively.
576+
- You can use LaTeX syntax in your responses to render mathematical expressions
576577
577578
====
578579

src/core/webview/index.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
181181
"codicon.css",
182182
])
183183

184+
const katexCssUri = getUri(webview, this.context.extensionUri, [
185+
"webview-ui",
186+
"node_modules",
187+
"katex",
188+
"dist",
189+
"katex.min.css",
190+
])
191+
184192
// const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, "assets", "main.js"))
185193

186194
// const styleResetUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, "assets", "reset.css"))
@@ -204,24 +212,25 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
204212

205213
// Tip: Install the es6-string-html VS Code extension to enable code highlighting below
206214
return /*html*/ `
207-
<!DOCTYPE html>
208-
<html lang="en">
209-
<head>
210-
<meta charset="utf-8">
211-
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
212-
<meta name="theme-color" content="#000000">
213-
<link rel="stylesheet" type="text/css" href="${stylesUri}">
214-
<link href="${codiconsUri}" rel="stylesheet" />
215-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; connect-src https://*.posthog.com https://*.firebaseauth.com https://*.firebaseio.com https://*.googleapis.com https://*.firebase.com; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https: data:; script-src 'nonce-${nonce}' 'unsafe-eval';">
216-
<title>Cline</title>
217-
</head>
218-
<body>
219-
<noscript>You need to enable JavaScript to run this app.</noscript>
220-
<div id="root"></div>
221-
<script type="module" nonce="${nonce}" src="${scriptUri}"></script>
222-
</body>
223-
</html>
224-
`
215+
<!DOCTYPE html>
216+
<html lang="en">
217+
<head>
218+
<meta charset="utf-8">
219+
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
220+
<meta name="theme-color" content="#000000">
221+
<link rel="stylesheet" type="text/css" href="${stylesUri}">
222+
<link href="${codiconsUri}" rel="stylesheet" />
223+
<link href="${katexCssUri}" rel="stylesheet" />
224+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; connect-src https://*.posthog.com https://*.firebaseauth.com https://*.firebaseio.com https://*.googleapis.com https://*.firebase.com; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https: data:; script-src 'nonce-${nonce}' 'unsafe-eval';">
225+
<title>Cline</title>
226+
</head>
227+
<body>
228+
<noscript>You need to enable JavaScript to run this app.</noscript>
229+
<div id="root"></div>
230+
<script type="module" nonce="${nonce}" src="${scriptUri}"></script>
231+
</body>
232+
</html>
233+
`
225234
}
226235

227236
/**
@@ -256,6 +265,15 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
256265
"codicon.css",
257266
])
258267

268+
// Get KaTeX resources
269+
const katexCssUri = getUri(webview, this.context.extensionUri, [
270+
"webview-ui",
271+
"node_modules",
272+
"katex",
273+
"dist",
274+
"katex.min.css",
275+
])
276+
259277
const scriptEntrypoint = "src/main.tsx"
260278
const scriptUri = `http://${localServerUrl}/${scriptEntrypoint}`
261279

@@ -271,7 +289,7 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
271289

272290
const csp = [
273291
"default-src 'none'",
274-
`font-src ${webview.cspSource}`,
292+
`font-src ${webview.cspSource} data:`,
275293
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
276294
`img-src ${webview.cspSource} https: data:`,
277295
`script-src 'unsafe-eval' https://* http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`,
@@ -287,6 +305,7 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
287305
<meta http-equiv="Content-Security-Policy" content="${csp.join("; ")}">
288306
<link rel="stylesheet" type="text/css" href="${stylesUri}">
289307
<link href="${codiconsUri}" rel="stylesheet" />
308+
<link href="${katexCssUri}" rel="stylesheet" />
290309
<title>Cline</title>
291310
</head>
292311
<body>

src/integrations/notifications/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function showSystemNotification(options: NotificationOptions): Prom
7474
const escapedOptions = {
7575
...options,
7676
title: title.replace(/"/g, '\\"'),
77-
message: message.replace(/"/g, '\\"'),
77+
message: message.replace(/\\/g, "\\\\").replace(/"/g, '\\"'),
7878
subtitle: options.subtitle?.replace(/"/g, '\\"') || "",
7979
}
8080

0 commit comments

Comments
 (0)