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