mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-30 08:17:20 +00:00
Add to do list support to markdown (#10129)
This commit is contained in:
parent
bbbeafcc92
commit
2c2809573f
@ -11,6 +11,28 @@ interface WhiteList {
|
|||||||
let whiteListNormal: WhiteList | undefined;
|
let whiteListNormal: WhiteList | undefined;
|
||||||
let whiteListSvg: 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 = (
|
const renderMarkdown = (
|
||||||
content: string,
|
content: string,
|
||||||
markedOptions: marked.MarkedOptions,
|
markedOptions: marked.MarkedOptions,
|
||||||
@ -22,6 +44,7 @@ const renderMarkdown = (
|
|||||||
if (!whiteListNormal) {
|
if (!whiteListNormal) {
|
||||||
whiteListNormal = {
|
whiteListNormal = {
|
||||||
...(getDefaultWhiteList() as WhiteList),
|
...(getDefaultWhiteList() as WhiteList),
|
||||||
|
input: ["type", "disabled", "checked"],
|
||||||
"ha-icon": ["icon"],
|
"ha-icon": ["icon"],
|
||||||
"ha-svg-icon": ["path"],
|
"ha-svg-icon": ["path"],
|
||||||
};
|
};
|
||||||
@ -45,6 +68,7 @@ const renderMarkdown = (
|
|||||||
|
|
||||||
return filterXSS(marked(content, markedOptions), {
|
return filterXSS(marked(content, markedOptions), {
|
||||||
whiteList,
|
whiteList,
|
||||||
|
onTagAttr,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user