Skip to content

Commit

Permalink
#113975 use insance to remove svgs tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jan 7, 2021
1 parent e803459 commit 23ac286
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/vs/workbench/contrib/extensions/browser/extensionEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,14 @@ import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/to
import { editorBackground } from 'vs/platform/theme/common/colorRegistry';
import { registerAction2, Action2 } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { insane } from 'vs/base/common/insane/insane';

function removeEmbeddedSVGs(documentContent: string): string {
const newDocument = new DOMParser().parseFromString(documentContent, 'text/html');

// remove all inline svgs
const allSVGs = newDocument.documentElement.querySelectorAll('svg');
if (allSVGs) {
for (let i = 0; i < allSVGs.length; i++) {
const svg = allSVGs[i];
if (svg.parentNode) {
svg.parentNode.removeChild(allSVGs[i]);
}
return insane(documentContent, {
filter(token: { tag: string, attrs: { readonly [key: string]: string } }): boolean {
return token.tag !== 'svg';
}
}

return newDocument.documentElement.outerHTML;
});
}

class NavBar extends Disposable {
Expand Down Expand Up @@ -645,8 +637,8 @@ export class ExtensionEditor extends EditorPane {
private async renderMarkdown(cacheResult: CacheResult<string>, template: IExtensionEditorTemplate) {
const contents = await this.loadContents(() => cacheResult, template);
const content = await renderMarkdownDocument(contents, this.extensionService, this.modeService);
const documentContent = await this.renderBody(content);
return removeEmbeddedSVGs(documentContent);
const sanitizedContent = removeEmbeddedSVGs(content);
return await this.renderBody(sanitizedContent);
}

private async renderBody(body: string): Promise<string> {
Expand Down

0 comments on commit 23ac286

Please sign in to comment.