1
This commit is contained in:
@@ -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) { // 文本节点
|
||||||
$(this).replaceWith(this.nodeValue.replace(/ /g, ' '));
|
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>
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user