From a373ee716341edb715206287cbda445514ce4441 Mon Sep 17 00:00:00 2001 From: liangjiami <2249412933@qq.com> Date: Thu, 17 Jul 2025 15:08:52 +0800 Subject: [PATCH] 1 --- .../view/mobile/topic_nas/help_detail.html | 47 +++++++++---------- public/static/index/mobile/css/public.css | 13 ++--- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/index/view/mobile/topic_nas/help_detail.html b/app/index/view/mobile/topic_nas/help_detail.html index a33dc57c..465f83d0 100644 --- a/app/index/view/mobile/topic_nas/help_detail.html +++ b/app/index/view/mobile/topic_nas/help_detail.html @@ -173,33 +173,30 @@ }, 300); }); // 英文截断 - // 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, ' ')) - ); - } - }); - } - - // 2. 初始化处理 - convertNbspToSpace(); - - // 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-container')[0], { - childList: true, - subtree: true + function processContent() { + $('#rendered-content').html(function(i, html) { + // 处理空行 + html = html.replace(/(<(p|h[1-6]|div)[^>]*>)\s*( )*\s*(<\/\2>)/g, function(match, p1, p2, p3, p4) { + return p1 + ' ' + p4; }); + + // 替换其他 为普通空格,但保留数字后的 (如版本号) + html = html.replace(/([^0-9]) /g, '$1 '); + + // 处理英文单词间的多个空格 + html = html.replace(/([a-zA-Z])\s+([a-zA-Z])/g, '$1 $2'); + + return html; + }); + + // 添加CSS类而不是直接内联样式 + $('#rendered-content').addClass('word-wrap-optimized'); } + + // 初始处理 + processContent(); + + // 如果内容是异步加载的,可以在加载完成后调用processContent() }); {/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 a1ee7575..6db34591 100755 --- a/public/static/index/mobile/css/public.css +++ b/public/static/index/mobile/css/public.css @@ -170,8 +170,9 @@ body { -moz-tab-size: 4; text-align: left; word-wrap: break-word; - overflow-wrap: anywhere; - white-space: normal !important; + overflow-wrap: break-word; + word-break: normal; + white-space: normal; } .ql-editor>* { @@ -184,10 +185,10 @@ body { margin: 0; padding: 0; counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9; - word-break: normal; - overflow-wrap: anywhere; /* 更智能的换行方式 */ - display: inline-block; /* 创建换行上下文 */ - max-width: 100%; + word-wrap: break-word; + overflow-wrap: break-word; + word-break: keep-all; + white-space: normal; } /* 移动端优化 */ @media (max-width: 768px) {