Render checkboxes in markdown (#200846)

Fixes microsoft/vscode-pull-request-github#5310
This commit is contained in:
Alex Ross
2023-12-19 10:41:37 +01:00
committed by GitHub
parent 14f6a2a10f
commit 2f3b5d835c
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -1817,6 +1817,7 @@ export const basicMarkupHtmlTags = Object.freeze([
'hr',
'i',
'img',
'input',
'ins',
'kbd',
'label',
+20
View File
@@ -388,9 +388,26 @@ function sanitizeRenderedMarkdown(
}
e.keepAttr = false;
return;
} else if (element.tagName === 'INPUT' && element.attributes.getNamedItem('type')?.value === 'checkbox') {
if ((e.attrName === 'type' && e.attrValue === 'checkbox') || e.attrName === 'disabled' || e.attrName === 'checked') {
e.keepAttr = true;
return;
}
e.keepAttr = false;
}
});
dompurify.addHook('uponSanitizeElement', (element, e) => {
if (e.tagName === 'input') {
if (element.attributes.getNamedItem('type')?.value === 'checkbox') {
element.setAttribute('disabled', '');
} else {
element.parentElement?.removeChild(element);
}
}
});
const hook = DOM.hookDomPurifyHrefAndSrcSanitizer(allowedSchemes);
try {
@@ -405,10 +422,12 @@ export const allowedMarkdownAttr = [
'align',
'autoplay',
'alt',
'checked',
'class',
'controls',
'data-code',
'data-href',
'disabled',
'draggable',
'height',
'href',
@@ -420,6 +439,7 @@ export const allowedMarkdownAttr = [
'style',
'target',
'title',
'type',
'width',
'start',
];