[fix] added strikethrough, tables, youtube iframe support

This commit is contained in:
kwaroran
2023-05-18 23:16:46 +09:00
parent 9ec26477eb
commit 06b9a53a90

View File

@@ -1,12 +1,26 @@
import DOMPurify from 'isomorphic-dompurify';
import showdown from 'showdown';
const convertor = new showdown.Converter()
convertor.setOption('simpleLineBreaks', true);
const convertor = new showdown.Converter({
simpleLineBreaks: true,
strikethrough: true,
tables: true
})
DOMPurify.addHook("uponSanitizeElement", (node: HTMLElement, data) => {
if (data.tagName === "iframe") {
const src = node.getAttribute("src") || "";
if (!src.startsWith("https://www.youtube.com/embed/")) {
return node.parentNode.removeChild(node);
}
}
});
export function ParseMarkdown(data:string) {
return DOMPurify.sanitize(convertor.makeHtml(data), {
FORBID_TAGS: []
ADD_TAGS: ["iframe"],
ADD_ATTR: ["allow", "allowfullscreen", "frameborder", "scrolling"],
})
}