From 07692a2a29fd9a9a50cbe3c645a4f51c56ff2819 Mon Sep 17 00:00:00 2001 From: liangjiami <2249412933@qq.com> Date: Thu, 17 Jul 2025 12:00:46 +0800 Subject: [PATCH] 1 --- .../view/mobile/topic_nas/help_detail.html | 65 +++++++------------ public/static/index/mobile/css/public.css | 28 ++++---- 2 files changed, 38 insertions(+), 55 deletions(-) diff --git a/app/index/view/mobile/topic_nas/help_detail.html b/app/index/view/mobile/topic_nas/help_detail.html index 2ab88df5..a33dc57c 100644 --- a/app/index/view/mobile/topic_nas/help_detail.html +++ b/app/index/view/mobile/topic_nas/help_detail.html @@ -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 $('').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 = $('').addClass('space-replaced'); + $(this).replaceWith( + $span.html(this.nodeValue.replace(/ /g, ' ')) + ); + } }); - - // 保护特定术语不换行 - const protectedTerms = ['launch parameters', 'specific files']; - protectedTerms.forEach(term => { - text = text.replace(new RegExp(term, 'gi'), term.replace(/ /g, ' ')); - }); - - $this.html(text); - }); - } + } - // 初始处理 - applySmartWrapping(); + // 2. 初始化处理 + convertNbspToSpace(); - // 3. 监听动态内容变化 - if (typeof MutationObserver !== 'undefined') { - const observer = new MutationObserver(function(mutations) { - mutations.forEach(function() { - applySmartWrapping(); + // 3. 监听动态内容变化 + if (typeof MutationObserver !== 'undefined') { + const observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + $(mutation.addedNodes).find('.ql-editor').each(convertNbspToSpace); }); - }); - observer.observe($('.ql-editor')[0], { + }); + observer.observe($('.ql-container')[0], { childList: true, - subtree: true, - characterData: true - }); - } + subtree: true + }); + } }); {/block} \ No newline at end of file diff --git a/public/static/index/mobile/css/public.css b/public/static/index/mobile/css/public.css index c426bffb..a1ee7575 100755 --- a/public/static/index/mobile/css/public.css +++ b/public/static/index/mobile/css/public.css @@ -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;