Skip to content

Commit 1cd8ad3

Browse files
committed
Allow svg paths for rendered math
Fixes microsoft#259148
1 parent bbd1961 commit 1cd8ad3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/vs/base/browser/markdownRenderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export interface MarkdownSanitizerConfig {
5656
readonly allowedTags?: {
5757
readonly override: readonly string[];
5858
};
59+
readonly allowedAttributes?: {
60+
readonly override: readonly string[];
61+
};
5962
readonly customAttrSanitizer?: (attrName: string, attrValue: string) => boolean | string;
6063
readonly allowedLinkSchemes?: {
6164
readonly augment: readonly string[];
@@ -510,7 +513,7 @@ function getDomSanitizerConfig(isTrusted: boolean | MarkdownStringTrustedOptions
510513
override: options.allowedTags?.override ?? allowedMarkdownHtmlTags
511514
},
512515
allowedAttributes: {
513-
override: allowedMarkdownHtmlAttributes,
516+
override: options.allowedAttributes?.override ?? allowedMarkdownHtmlAttributes,
514517
},
515518
allowedLinkProtocols: {
516519
override: allowedLinkSchemes,

src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,27 @@ export class MarkedKatexSupport {
2222
...trustedMathMlTags,
2323
]
2424
},
25+
allowedAttributes: {
26+
override: [
27+
...baseConfig.allowedAttributes,
28+
// Math
29+
'stretchy',
30+
'encoding',
31+
'accent',
32+
// SVG
33+
'd',
34+
'viewBox',
35+
'preserveAspectRatio',
36+
]
37+
},
2538
customAttrSanitizer: (attrName, attrValue) => {
2639
if (attrName === 'class') {
2740
return true; // TODO: allows all classes for now since we don't have a list of possible katex classes
2841
} else if (attrName === 'style') {
2942
return this.sanitizeKatexStyles(attrValue);
3043
}
3144

32-
return baseConfig.allowedAttributes.includes(attrName);
45+
return true; // Allow through other attrs. Our allow list already filtered out bad ones
3346
},
3447
};
3548
}

0 commit comments

Comments
 (0)