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

View File

@@ -172,6 +172,29 @@
}) })
}, 300); }, 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> </script>
{/block} {/block}

View File

@@ -156,12 +156,12 @@ body {
-moz-tab-size: 4; -moz-tab-size: 4;
text-align: left; text-align: left;
word-wrap: normal; word-wrap: normal;
overflow-wrap: normal;
word-break: normal;
hyphens: manual;
white-space: normal;
}
}
.word-wrapper {
display: inline-block;
max-width: 100%;
}
.ql-editor>* { .ql-editor>* {
cursor: text; cursor: text;
word-break: normal; word-break: normal;
@@ -172,8 +172,6 @@ body {
margin: 0; margin: 0;
padding: 0; padding: 0;
counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
overflow-wrap: anywhere;
word-break: keep-all;
} }
.ql-editor ol,.ql-editor ul { .ql-editor ol,.ql-editor ul {