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:
Matt Bierner
2021-09-03 12:33:00 -07:00
committed by GitHub
parent 474d4951d8
commit 8b7264a91d
7 changed files with 83 additions and 16 deletions

View File

@@ -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;
}

View File

@@ -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