Skip to content

Commit b7a9323

Browse files
authored
Fix images in open current file as release notes (microsoft#230245)
* Fix images in open current file as release notes * Remove `disableServiceWorker`
1 parent c5b6ef1 commit b7a9323

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts

+23-10
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ import { SimpleSettingRenderer } from '../../markdown/browser/markdownSettingRen
3434
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
3535
import { Schemas } from '../../../../base/common/network.js';
3636
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
37+
import { dirname } from '../../../../base/common/resources.js';
38+
import { asWebviewUri } from '../../webview/common/webview.js';
3739

3840
export class ReleaseNotesManager {
3941
private readonly _simpleSettingRenderer: SimpleSettingRenderer;
4042
private readonly _releaseNotesCache = new Map<string, Promise<string>>();
4143

4244
private _currentReleaseNotes: WebviewInput | undefined = undefined;
43-
private _lastText: string | undefined;
45+
private _lastMeta: { text: string; base: URI } | undefined;
4446
private readonly disposables = new DisposableStore();
4547

4648
public constructor(
@@ -68,19 +70,30 @@ export class ReleaseNotesManager {
6870
}
6971

7072
private async updateHtml() {
71-
if (!this._currentReleaseNotes || !this._lastText) {
73+
if (!this._currentReleaseNotes || !this._lastMeta) {
7274
return;
7375
}
74-
const html = await this.renderBody(this._lastText);
76+
const html = await this.renderBody(this._lastMeta);
7577
if (this._currentReleaseNotes) {
7678
this._currentReleaseNotes.webview.setHtml(html);
7779
}
7880
}
7981

82+
private async getBase(useCurrentFile: boolean) {
83+
if (useCurrentFile) {
84+
const currentFileUri = this._codeEditorService.getActiveCodeEditor()?.getModel()?.uri;
85+
if (currentFileUri) {
86+
return dirname(currentFileUri);
87+
}
88+
}
89+
return URI.parse('https://code.visualstudio.com/raw');
90+
}
91+
8092
public async show(version: string, useCurrentFile: boolean): Promise<boolean> {
8193
const releaseNoteText = await this.loadReleaseNotes(version, useCurrentFile);
82-
this._lastText = releaseNoteText;
83-
const html = await this.renderBody(releaseNoteText);
94+
const base = await this.getBase(useCurrentFile);
95+
this._lastMeta = { text: releaseNoteText, base };
96+
const html = await this.renderBody(this._lastMeta);
8497
const title = nls.localize('releaseNotesInputName', "Release Notes: {0}", version);
8598

8699
const activeEditorPane = this._editorService.activeEditorPane;
@@ -95,10 +108,10 @@ export class ReleaseNotesManager {
95108
options: {
96109
tryRestoreScrollPosition: true,
97110
enableFindWidget: true,
98-
disableServiceWorker: true,
111+
disableServiceWorker: useCurrentFile ? false : true,
99112
},
100113
contentOptions: {
101-
localResourceRoots: [],
114+
localResourceRoots: useCurrentFile ? [base] : [],
102115
allowScripts: true
103116
},
104117
extension: undefined
@@ -247,10 +260,10 @@ export class ReleaseNotesManager {
247260
return uri;
248261
}
249262

250-
private async renderBody(text: string) {
263+
private async renderBody(fileContent: { text: string; base: URI }) {
251264
const nonce = generateUuid();
252265

253-
const content = await renderMarkdownDocument(text, this._extensionService, this._languageService, {
266+
const content = await renderMarkdownDocument(fileContent.text, this._extensionService, this._languageService, {
254267
shouldSanitize: false,
255268
markedExtensions: [{
256269
renderer: {
@@ -266,7 +279,7 @@ export class ReleaseNotesManager {
266279
return `<!DOCTYPE html>
267280
<html>
268281
<head>
269-
<base href="https://code.visualstudio.com/raw/">
282+
<base href="${asWebviewUri(fileContent.base).toString(true)}/" >
270283
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
271284
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; style-src 'nonce-${nonce}' https://code.visualstudio.com; script-src 'nonce-${nonce}';">
272285
<style nonce="${nonce}">

0 commit comments

Comments
 (0)