Skip to content

Commit 8c71154

Browse files
authored
Support workspace images in markdown cells (#11086)
For #10893
1 parent 8dcaaff commit 8c71154

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

news/2 Fixes/11040.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure images in workspace folder are supported within markdown cells in a `Notebook`.

src/client/common/application/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,11 @@ export interface IWebPanelOptions {
10941094
listener: IWebPanelMessageListener;
10951095
title: string;
10961096
rootPath: string;
1097+
/**
1098+
* Additional paths apart from cwd and rootPath, that webview would allow loading resources/files from.
1099+
* E.g. required for webview to serve images from worksapces when nb is in a nested folder.
1100+
*/
1101+
additionalPaths?: string[];
10971102
scripts: string[];
10981103
startHttpServer: boolean;
10991104
cwd: string;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class WebPanelProvider implements IWebPanelProvider {
3030
// Allow loading resources from the `<extension folder>/tmp` folder when in webiviews.
3131
// Used by widgets to place files that are not otherwise accessible.
3232
const additionalRootPaths = [Uri.file(path.join(this.context.extensionPath, 'tmp'))];
33+
if (Array.isArray(options.additionalPaths)) {
34+
additionalRootPaths.push(...options.additionalPaths.map((item) => Uri.file(item)));
35+
}
3336
return new WebPanel(
3437
this.fs,
3538
this.disposableRegistry,

src/client/datascience/webViewHost.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ export abstract class WebViewHost<IMapping> implements IDisposable {
256256

257257
traceWarning(`startHttpServer=${startHttpServer}, will not be used. Temporarily turned off`);
258258

259+
const workspaceFolder = this.workspaceService.getWorkspaceFolder(Uri.file(cwd))?.uri;
260+
259261
// Use this script to create our web view panel. It should contain all of the necessary
260262
// script to communicate with this class.
261263
this.webPanel = await this.provider.create({
@@ -267,7 +269,8 @@ export abstract class WebViewHost<IMapping> implements IDisposable {
267269
settings,
268270
startHttpServer: false,
269271
cwd,
270-
webViewPanel
272+
webViewPanel,
273+
additionalPaths: workspaceFolder ? [workspaceFolder.fsPath] : []
271274
});
272275

273276
traceInfo('Web view created.');

0 commit comments

Comments
 (0)