This commit is contained in:
2025-07-17 11:30:52 +08:00
parent e736271536
commit 97b851e8a6
2 changed files with 28 additions and 7 deletions

View File

@@ -172,6 +172,29 @@
})
}, 300);
});
// 英文单词截断
// 1. 基础CSS保证必须
$('.ql-editor').css({
'word-break': 'normal',
'overflow-wrap': 'anywhere',
'overflow-x': 'hidden'
});
// 2. 智能处理文本节点
$('.ql-editor').contents().each(function() {
if (this.nodeType === 3) { // 只处理文本节点
const $wrapper = $('<span>').addClass('word-wrapper');
$(this).replaceWith($wrapper.text(this.nodeValue));
}
});
// 3. 处理长单词10个字符以上
$('.word-wrapper').html(function(_, html) {
return html.replace(/([a-zA-Z]{10,})/g, function(match) {
return match.replace(/([a-z])([A-Z])/g, '$1<wbr>$2')
.replace(/(.{5})/g, '$1<wbr>');
});
});
});
</script>
{/block}