1
This commit is contained in:
@@ -173,54 +173,33 @@
|
||||
}, 300);
|
||||
});
|
||||
// 英文截断
|
||||
// 1. 替换所有 为普通空格(保留连续空格)
|
||||
$('.ql-editor').html(function(_, html) {
|
||||
return html.replace(/ /g, ' ');
|
||||
});
|
||||
|
||||
// 2. 处理特殊换行情况
|
||||
function applySmartWrapping() {
|
||||
$('.ql-editor').find('*').contents().filter(function() {
|
||||
return this.nodeType === 3 && this.nodeValue.trim().length > 0;
|
||||
}).replaceWith(function() {
|
||||
return $('<span>').addClass('wrapped-text').text(this.nodeValue);
|
||||
});
|
||||
|
||||
$('.wrapped-text').each(function() {
|
||||
const $this = $(this);
|
||||
let text = $this.text();
|
||||
|
||||
// 处理超长连续字符串(20字符以上)
|
||||
text = text.replace(/([^\s]{20,})/g, function(match) {
|
||||
return match.replace(/(.{10})/g, '$1​');
|
||||
// 1. 替换 为特殊空白占位符
|
||||
function convertNbspToSpace() {
|
||||
$('.ql-editor').contents().each(function() {
|
||||
if (this.nodeType === 3) { // 文本节点
|
||||
const $span = $('<span>').addClass('space-replaced');
|
||||
$(this).replaceWith(
|
||||
$span.html(this.nodeValue.replace(/ /g, '<span class="space-char"> </span>'))
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 保护特定术语不换行
|
||||
const protectedTerms = ['launch parameters', 'specific files'];
|
||||
protectedTerms.forEach(term => {
|
||||
text = text.replace(new RegExp(term, 'gi'), term.replace(/ /g, ' '));
|
||||
// 2. 初始化处理
|
||||
convertNbspToSpace();
|
||||
|
||||
// 3. 监听动态内容变化
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
$(mutation.addedNodes).find('.ql-editor').each(convertNbspToSpace);
|
||||
});
|
||||
|
||||
$this.html(text);
|
||||
});
|
||||
}
|
||||
|
||||
// 初始处理
|
||||
applySmartWrapping();
|
||||
|
||||
// 3. 监听动态内容变化
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function() {
|
||||
applySmartWrapping();
|
||||
});
|
||||
});
|
||||
observer.observe($('.ql-editor')[0], {
|
||||
observer.observe($('.ql-container')[0], {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true
|
||||
});
|
||||
}
|
||||
subtree: true
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{/block}
|
||||
@@ -144,7 +144,21 @@ body {
|
||||
margin: 0;
|
||||
padding: 0
|
||||
}
|
||||
|
||||
/* 空白占位符样式 */
|
||||
.space-char {
|
||||
display: inline;
|
||||
white-space: pre; /* 保留空白 */
|
||||
position: relative;
|
||||
padding-right: 0.15em; /* 视觉间距补偿 */
|
||||
}
|
||||
.space-char:after {
|
||||
content: " ";
|
||||
visibility: hidden;
|
||||
}
|
||||
.space-replaced {
|
||||
display: inline;
|
||||
white-space: normal;
|
||||
}
|
||||
.ql-editor {
|
||||
box-sizing: border-box;
|
||||
line-height: 1.42;
|
||||
@@ -157,19 +171,9 @@ body {
|
||||
text-align: left;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: normal;
|
||||
white-space: normal !important;
|
||||
}
|
||||
|
||||
}
|
||||
.word-wrapper {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
}
|
||||
/* 保护重要术语不换行 */
|
||||
.protected-term {
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
}
|
||||
.ql-editor>* {
|
||||
cursor: text;
|
||||
word-break: normal;
|
||||
|
||||
Reference in New Issue
Block a user