Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render checkboxes in markdown #200846

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,7 @@ export const basicMarkupHtmlTags = Object.freeze([
'hr',
'i',
'img',
'input',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjbvz, I just noticed that this array is also used here:

ALLOWED_TAGS: [
...basicMarkupHtmlTags,
'checkbox',
'checklist',
],

Is this still ok?

'ins',
'kbd',
'label',
Expand Down
20 changes: 20 additions & 0 deletions src/vs/base/browser/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -405,10 +422,12 @@ export const allowedMarkdownAttr = [
'align',
'autoplay',
'alt',
'checked',
'class',
'controls',
'data-code',
'data-href',
'disabled',
'draggable',
'height',
'href',
Expand All @@ -420,6 +439,7 @@ export const allowedMarkdownAttr = [
'style',
'target',
'title',
'type',
'width',
'start',
];
Expand Down