[feat] css full support
This commit is contained in:
@@ -4,6 +4,7 @@ import { DataBase, type character, type groupChat } from './storage/database';
|
||||
import { getFileSrc } from './storage/globalApi';
|
||||
import { processScript } from './process/scripts';
|
||||
import { get } from 'svelte/store';
|
||||
import css from '@adobe/css-tools'
|
||||
|
||||
const convertor = new showdown.Converter({
|
||||
simpleLineBreaks: true,
|
||||
@@ -27,6 +28,28 @@ DOMPurify.addHook("uponSanitizeElement", (node: HTMLElement, data) => {
|
||||
return node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
if(data.tagName === 'style'){
|
||||
try {
|
||||
const ast = css.parse(node.innerHTML)
|
||||
const rules = ast?.stylesheet?.rules
|
||||
if(rules){
|
||||
for(const rule of rules){
|
||||
if(rule.selectors){
|
||||
for(let i=0;i<rule.selectors.length;i++){
|
||||
rule.selectors[i] = ".chattext " + rule.selectors[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
node.innerHTML = css.stringify(ast)
|
||||
|
||||
} catch (error) {
|
||||
const ErrorNode = document.createElement("div")
|
||||
ErrorNode.innerText = `CSS ERROR: ${error}`
|
||||
node.parentNode.appendChild(ErrorNode)
|
||||
return node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
|
||||
Reference in New Issue
Block a user