Skip to content

Commit f4b7481

Browse files
authored
Add support for local images in markdown cells (microsoft#9486)
* Add support for local images * Fix formatting
1 parent 90f234f commit f4b7481

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

news/1 Enhancements/7704.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for rendering local images within markdown cells in the `Notebook Editor`.

src/client/common/application/webPanels/webPanel.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class WebPanel implements IWebPanel {
3838
{
3939
enableScripts: true,
4040
retainContextWhenHidden: true,
41-
localResourceRoots: [Uri.file(this.options.rootPath)],
41+
localResourceRoots: [Uri.file(this.options.rootPath), Uri.file(this.options.cwd)],
4242
enableFindWidget: true,
4343
portMapping: port ? [{ webviewPort: RemappedPort, extensionHostPort: port }] : undefined
4444
}
@@ -129,19 +129,21 @@ export class WebPanel implements IWebPanel {
129129

130130
// tslint:disable-next-line:no-any
131131
private generateLocalReactHtml(webView: Webview) {
132-
const uriBase = webView.asWebviewUri(Uri.file(this.options.rootPath));
132+
const uriBase = webView.asWebviewUri(Uri.file(this.options.cwd)).toString();
133133
const uris = this.options.scripts.map(script => webView.asWebviewUri(Uri.file(script)));
134134

135135
return `<!doctype html>
136136
<html lang="en">
137137
<head>
138138
<meta charset="utf-8">
139139
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
140-
<meta http-equiv="Content-Security-Policy" content="img-src 'self' data: https: http: blob:; default-src 'unsafe-inline' 'unsafe-eval' vscode-resource: data: https: http: blob:;">
140+
<meta http-equiv="Content-Security-Policy" content="img-src 'self' data: https: http: blob: ${
141+
webView.cspSource
142+
}; default-src 'unsafe-inline' 'unsafe-eval' vscode-resource: data: https: http: blob:;">
141143
<meta name="theme-color" content="#000000">
142144
<meta name="theme" content="${Identifiers.GeneratedThemeName}"/>
143145
<title>React App</title>
144-
<base href="${uriBase}"/>
146+
<base href="${uriBase}${uriBase.endsWith('/') ? '' : '/'}"/>
145147
</head>
146148
<body>
147149
<noscript>You need to enable JavaScript to run this app.</noscript>

0 commit comments

Comments
 (0)