1
This commit is contained in:
@@ -176,33 +176,26 @@
|
|||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
// 英文截断处理
|
// 英文截断处理
|
||||||
$('#rendered-content').css({
|
// 目标容器:富文本内容所在的元素
|
||||||
'word-wrap': 'break-word',
|
const contentContainer = $('#rendered-content');
|
||||||
'overflow-wrap': 'break-word',
|
|
||||||
'word-break': 'normal',
|
// 遍历所有包含文本内容的标签(p、h1-h6、strong等)
|
||||||
'white-space': 'normal',
|
contentContainer.find('*').each(function() {
|
||||||
|
const $element = $(this);
|
||||||
|
const htmlContent = $element.html();
|
||||||
|
|
||||||
|
// 条件1:排除内容仅为一个 的标签(如<p> </p>)
|
||||||
|
if (htmlContent.trim() === ' ') {
|
||||||
|
return; // 不处理,继续下一个元素
|
||||||
|
}
|
||||||
|
|
||||||
|
// 条件2:检查是否包含 且有实际文本内容
|
||||||
|
if (htmlContent.includes(' ')) {
|
||||||
|
// 将所有 替换为普通空格(有效占位符,支持单词完整换行)
|
||||||
|
const newContent = htmlContent.replace(/ /g, ' ');
|
||||||
|
$element.html(newContent);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 处理函数
|
|
||||||
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>
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user