This commit is contained in:
2025-07-17 16:49:03 +08:00
parent db744f3081
commit e6da274663

View File

@@ -183,12 +183,26 @@
'white-space': 'normal',
});
// 处理文本节点
$('#rendered-content').find('*').contents().filter(function() {
return this.nodeType === 3;
}).each(function() {
// 处理函数
function processTextNodes($element) {
$element.contents().each(function() {
if (this.nodeType === 3) { // 文本节点
let $parent = $(this).parent();
let cleanHtml = $parent.html()
.replace(/<[^>]+>/g, '') // 移除所有标签
.replace(/\s/g, ''); // 移除所有空白
if (cleanHtml !== '&nbsp;') {
$(this).replaceWith(this.nodeValue.replace(/&nbsp;/g, ' '));
}
} else if (this.nodeType === 1) { // 元素节点
processTextNodes($(this));
}
});
}
// 执行处理
processTextNodes($('#rendered-content'));
});
</script>
{/block}