1
This commit is contained in:
@@ -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 !== ' ') {
|
||||
$(this).replaceWith(this.nodeValue.replace(/ /g, ' '));
|
||||
}
|
||||
} else if (this.nodeType === 1) { // 元素节点
|
||||
processTextNodes($(this));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 执行处理
|
||||
processTextNodes($('#rendered-content'));
|
||||
});
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user