Add to do list support to markdown (#10129)

This commit is contained in:
Kyle Niewiada 2021-10-22 11:49:00 -04:00 committed by GitHub
parent bbbeafcc92
commit 2c2809573f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,28 @@ interface WhiteList {
let whiteListNormal: WhiteList | undefined;
let whiteListSvg: WhiteList | undefined;
// Override the default `onTagAttr` behavior to only render
// our markdown checkboxes.
// Returning undefined causes the default measure to be taken
// in the xss library.
const onTagAttr = (
tag: string,
name: string,
value: string
): string | undefined => {
if (tag === "input") {
if (
(name === "type" && value === "checkbox") ||
name === "checked" ||
name === "disabled"
) {
return undefined;
}
return "";
}
return undefined;
};
const renderMarkdown = (
content: string,
markedOptions: marked.MarkedOptions,
@ -22,6 +44,7 @@ const renderMarkdown = (
if (!whiteListNormal) {
whiteListNormal = {
...(getDefaultWhiteList() as WhiteList),
input: ["type", "disabled", "checked"],
"ha-icon": ["icon"],
"ha-svg-icon": ["path"],
};
@ -45,6 +68,7 @@ const renderMarkdown = (
return filterXSS(marked(content, markedOptions), {
whiteList,
onTagAttr,
});
};