feat: kofi + update dompurify function

This commit is contained in:
SethBurkart123
2025-02-27 17:20:27 +11:00
parent 4703d68bac
commit 3277b02dfb
3 changed files with 22 additions and 3 deletions
+11 -3
View File
@@ -1,12 +1,20 @@
import DOMPurify from 'dompurify';
export default function stringToHTML(str: string, styles = false) {
var parser = new DOMParser();
str = DOMPurify.sanitize(str, { ADD_ATTR: ['onclick'] });
var doc = parser.parseFromString(str, 'text/html');
const parser = new DOMParser();
str = DOMPurify.sanitize(str, {
ADD_ATTR: ['onclick'],
ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|chrome-extension):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
});
const doc = parser.parseFromString(str, 'text/html');
if (styles) {
doc.body.style.cssText =
'height: auto; overflow: scroll; margin: 0px; background: var(--background-primary);';
}
return doc.body;
}