Не подтверждена Коммит b7a9323c создал по автору Alex Ross's avatar Alex Ross Зафиксировано автором GitHub
Просмотр файлов

Fix images in open current file as release notes (#230245)

* Fix images in open current file as release notes

* Remove `disableServiceWorker`
владелец c5b6ef14
......@@ -34,13 +34,15 @@ import { SimpleSettingRenderer } from '../../markdown/browser/markdownSettingRen
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { Schemas } from '../../../../base/common/network.js';
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
import { dirname } from '../../../../base/common/resources.js';
import { asWebviewUri } from '../../webview/common/webview.js';
export class ReleaseNotesManager {
private readonly _simpleSettingRenderer: SimpleSettingRenderer;
private readonly _releaseNotesCache = new Map<string, Promise<string>>();
private _currentReleaseNotes: WebviewInput | undefined = undefined;
private _lastText: string | undefined;
private _lastMeta: { text: string; base: URI } | undefined;
private readonly disposables = new DisposableStore();
public constructor(
......@@ -68,19 +70,30 @@ export class ReleaseNotesManager {
}
private async updateHtml() {
if (!this._currentReleaseNotes || !this._lastText) {
if (!this._currentReleaseNotes || !this._lastMeta) {
return;
}
const html = await this.renderBody(this._lastText);
const html = await this.renderBody(this._lastMeta);
if (this._currentReleaseNotes) {
this._currentReleaseNotes.webview.setHtml(html);
}
}
private async getBase(useCurrentFile: boolean) {
if (useCurrentFile) {
const currentFileUri = this._codeEditorService.getActiveCodeEditor()?.getModel()?.uri;
if (currentFileUri) {
return dirname(currentFileUri);
}
}
return URI.parse('https://code.visualstudio.com/raw');
}
public async show(version: string, useCurrentFile: boolean): Promise<boolean> {
const releaseNoteText = await this.loadReleaseNotes(version, useCurrentFile);
this._lastText = releaseNoteText;
const html = await this.renderBody(releaseNoteText);
const base = await this.getBase(useCurrentFile);
this._lastMeta = { text: releaseNoteText, base };
const html = await this.renderBody(this._lastMeta);
const title = nls.localize('releaseNotesInputName', "Release Notes: {0}", version);
const activeEditorPane = this._editorService.activeEditorPane;
......@@ -95,10 +108,10 @@ export class ReleaseNotesManager {
options: {
tryRestoreScrollPosition: true,
enableFindWidget: true,
disableServiceWorker: true,
disableServiceWorker: useCurrentFile ? false : true,
},
contentOptions: {
localResourceRoots: [],
localResourceRoots: useCurrentFile ? [base] : [],
allowScripts: true
},
extension: undefined
......@@ -247,10 +260,10 @@ export class ReleaseNotesManager {
return uri;
}
private async renderBody(text: string) {
private async renderBody(fileContent: { text: string; base: URI }) {
const nonce = generateUuid();
const content = await renderMarkdownDocument(text, this._extensionService, this._languageService, {
const content = await renderMarkdownDocument(fileContent.text, this._extensionService, this._languageService, {
shouldSanitize: false,
markedExtensions: [{
renderer: {
......@@ -266,7 +279,7 @@ export class ReleaseNotesManager {
return `<!DOCTYPE html>
<html>
<head>
<base href="https://code.visualstudio.com/raw/">
<base href="${asWebviewUri(fileContent.base).toString(true)}/" >
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<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}';">
<style nonce="${nonce}">
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать