This commit is contained in:
2025-07-17 16:49:03 +08:00
parent f211f58068
commit 5db4263f67

View File

@@ -183,12 +183,26 @@
'white-space': 'normal', 'white-space': 'normal',
}); });
// 处理文本节点 // 处理函数
$('#rendered-content').find('*').contents().filter(function() { function processTextNodes($element) {
return this.nodeType === 3; $element.contents().each(function() {
}).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, ' ')); $(this).replaceWith(this.nodeValue.replace(/&nbsp;/g, ' '));
}
} else if (this.nodeType === 1) { // 元素节点
processTextNodes($(this));
}
}); });
}
// 执行处理
processTextNodes($('#rendered-content'));
}); });
</script> </script>
{/block} {/block}