fix(parser): 解决样式不生效问题,后续待优化

This commit is contained in:
BTMuli
2023-04-02 18:04:14 +08:00
parent 9e216514fb
commit 9d756b8d96
5 changed files with 32 additions and 13 deletions

View File

@@ -15,13 +15,30 @@ export function parseAnnoContent(data: string): string {
const htmlBase = new DOMParser().parseFromString(data, "text/html");
// 遍历所有 span 标签
htmlBase.querySelectorAll("span").forEach(span => {
return (span.innerHTML = decodeRegExp(span.innerHTML));
if (span.style.fontSize) {
span.style.fontSize = "";
}
if (span.children.length === 0) {
return (span.innerHTML = decodeRegExp(span.innerHTML));
} else {
span.querySelectorAll("*").forEach(child => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 p 标签
htmlBase.querySelectorAll("p").forEach(p => {
// 如果没有子元素
if (p.children.length === 0) {
return (p.innerHTML = decodeRegExp(p.innerHTML));
} else {
p.querySelectorAll("*").forEach(child => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 a 标签