mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
Add MarkdownString.supportsHtml (#132182)
Fixes #40607 This change introduces a new `supportsHtml` property on `MarkdownString` that can be used to enable rendering of a safe subset of tags and attributes inside of markdown strings For backwards compatibility, `supportsHtml` will default to false and must be explicitly enabled by extensions This PR will need to go in after we adopt dompurify (#131950) which should provide better control over how we actually go about sanitizing rendered html
This commit is contained in:
@@ -280,7 +280,7 @@ export namespace MarkdownString {
|
||||
const { language, value } = markup;
|
||||
res = { value: '```' + language + '\n' + value + '\n```\n' };
|
||||
} else if (types.MarkdownString.isMarkdownString(markup)) {
|
||||
res = { value: markup.value, isTrusted: markup.isTrusted, supportThemeIcons: markup.supportThemeIcons };
|
||||
res = { value: markup.value, isTrusted: markup.isTrusted, supportThemeIcons: markup.supportThemeIcons, supportHtml: markup.supportHtml };
|
||||
} else if (typeof markup === 'string') {
|
||||
res = { value: markup };
|
||||
} else {
|
||||
@@ -345,6 +345,7 @@ export namespace MarkdownString {
|
||||
export function to(value: htmlContent.IMarkdownString): vscode.MarkdownString {
|
||||
const result = new types.MarkdownString(value.value, value.supportThemeIcons);
|
||||
result.isTrusted = value.isTrusted;
|
||||
result.supportHtml = value.supportHtml;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1343,6 +1343,14 @@ export class MarkdownString implements vscode.MarkdownString {
|
||||
this.#delegate.supportThemeIcons = value;
|
||||
}
|
||||
|
||||
get supportHtml(): boolean | undefined {
|
||||
return this.#delegate.supportHtml;
|
||||
}
|
||||
|
||||
set supportHtml(value: boolean | undefined) {
|
||||
this.#delegate.supportHtml = value;
|
||||
}
|
||||
|
||||
appendText(value: string): vscode.MarkdownString {
|
||||
this.#delegate.appendText(value);
|
||||
return this;
|
||||
@@ -1357,8 +1365,6 @@ export class MarkdownString implements vscode.MarkdownString {
|
||||
this.#delegate.appendCodeblock(language ?? '', value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@es5ClassCompat
|
||||
|
||||
Reference in New Issue
Block a user