Fix:修复添加了数学公式的节点,切换主题时文本样式没有改变的问题

This commit is contained in:
街角小林
2024-01-26 11:09:17 +08:00
parent 138cc4b3e8
commit 3405fb7e8a

View File

@@ -489,9 +489,27 @@ export const removeHtmlStyle = html => {
}
// 给html标签中指定的标签添加内联样式
let addHtmlStyleEl = null
export const addHtmlStyle = (html, tag, style) => {
const reg = new RegExp(`(<${tag}[^>]*)(>[^<>]*</${tag}>)`, 'g')
return html.replaceAll(reg, `$1 style="${style}"$2`)
if (!addHtmlStyleEl) {
addHtmlStyleEl = document.createElement('div')
}
addHtmlStyleEl.innerHTML = html
let walk = root => {
let childNodes = root.childNodes
childNodes.forEach(node => {
if (node.nodeType === 1) {
// 元素节点
if (node.tagName.toLowerCase() === tag) {
node.style.cssText = style
} else {
walk(node)
}
}
})
}
walk(addHtmlStyleEl)
return addHtmlStyleEl.innerHTML
}
// 检查一个字符串是否是富文本字符