From e3ee71e1a67c106e313ddcbe4ada6151b4b111b2 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 11 Jul 2025 09:09:35 -0700 Subject: [PATCH] Make sure we still allow other attrs in chat markdown Also fixes a class to correct some styling rules --- src/vs/base/browser/dom.ts | 4 +++- .../chat/browser/chatContentParts/chatMarkdownContentPart.ts | 2 +- .../workbench/contrib/markdown/browser/markedKatexSupport.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 8c0484bc21f..42fc0969568 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1846,9 +1846,11 @@ export const trustedMathMlTags = Object.freeze([ ]); +export const defaultAllowedAttrs = Object.freeze(['href', 'data-href', 'data-command', 'target', 'title', 'name', 'src', 'alt', 'class', 'id', 'role', 'tabindex', 'style', 'data-code', 'width', 'height', 'align', 'x-dispatch', 'required', 'checked', 'placeholder', 'type', 'start']); + const defaultDomPurifyConfig = Object.freeze({ ALLOWED_TAGS: ['a', 'button', 'blockquote', 'code', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'input', 'label', 'li', 'p', 'pre', 'select', 'small', 'span', 'strong', 'textarea', 'ul', 'ol'], - ALLOWED_ATTR: ['href', 'data-href', 'data-command', 'target', 'title', 'name', 'src', 'alt', 'class', 'id', 'role', 'tabindex', 'style', 'data-code', 'width', 'height', 'align', 'x-dispatch', 'required', 'checked', 'placeholder', 'type', 'start'], + ALLOWED_ATTR: [...defaultAllowedAttrs], RETURN_DOM: false, RETURN_DOM_FRAGMENT: false, RETURN_TRUSTED_TYPE: true diff --git a/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownContentPart.ts b/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownContentPart.ts index 2d24cd11391..6ee6043ce47 100644 --- a/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownContentPart.ts +++ b/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownContentPart.ts @@ -100,7 +100,7 @@ export class ChatMarkdownContentPart extends Disposable implements IChatContentP let thisPartCodeBlockIndexStart = 0; this.domNode = document.createElement('div'); - this.domNode.classList.add('chat-markdown-part'); + this.domNode.classList.add('chat-markdown-part', 'rendered-markdown'); const enableMath = configurationService.getValue(ChatConfiguration.EnableMath); diff --git a/src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts b/src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts index cb97d5f1170..0a71c2c568b 100644 --- a/src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts +++ b/src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts @@ -25,7 +25,7 @@ export class MarkedKatexSupport { return this.sanitizeKatexStyles(attrValue); } - return false; + return dom.defaultAllowedAttrs.includes(attrName); }, }; }