From 44e759564fd995b4d8c5c8f28fb43d165e592624 Mon Sep 17 00:00:00 2001 From: liangjiami <2249412933@qq.com> Date: Thu, 17 Jul 2025 15:18:38 +0800 Subject: [PATCH] 1 --- .../view/mobile/topic_nas/help_detail.html | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/app/index/view/mobile/topic_nas/help_detail.html b/app/index/view/mobile/topic_nas/help_detail.html index d423b941..a1fb65dc 100644 --- a/app/index/view/mobile/topic_nas/help_detail.html +++ b/app/index/view/mobile/topic_nas/help_detail.html @@ -173,30 +173,44 @@ }, 300); }); // 英文截断 - // 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; - // }); + // 处理 #rendered-content 内的内容 + $('#rendered-content').html(function(i, html) { + // 1. 先保护真正的空行(只包含 的标签) + html = html.replace(/<(p|h[1-6])>()?( | )*(<\/strong>)?<\/\1>/g, function(match) { + // 统一空行格式为

 

 

形式 + return match.replace(/(

|)\s*()?\s*( | )*\s*(<\/strong>)?\s*(<\/p>|<\/h[1-6]>)/, + function(m) { + var tag = m.match(/<(p|h[1-6])>/)[1]; + return '<' + tag + '> '; + }); + }); - // // 替换其他 为普通空格,但保留数字后的 (如版本号) - // html = html.replace(/([^0-9]) /g, '$1 '); + // 2. 替换其他 为普通空格(保留单词间的空格) + html = html.replace(/ (?=\w)/g, ' '); - // // 处理英文单词间的多个空格 - // html = html.replace(/([a-zA-Z])\s+([a-zA-Z])/g, '$1 $2'); - - // return html; - // }); - - // // 添加CSS类而不是直接内联样式 - // $('#rendered-content').addClass('word-wrap-optimized'); - // } + return html; + }); - // // 初始处理 - // processContent(); + // 添加CSS样式确保英文单词完整换行 + $('#rendered-content').css({ + 'word-wrap': 'break-word', + 'overflow-wrap': 'break-word', + 'word-break': 'normal', + 'white-space': 'normal' + }); - // 如果内容是异步加载的,可以在加载完成后调用processContent() + // 优化英文单词间的空格处理 + $('#rendered-content').find('p, h1, h2, h3, h4, h5, h6').each(function() { + var $el = $(this); + // 只处理非空行 + if ($el.html().trim() !== ' ') { + var html = $el.html() + .replace(/([a-zA-Z])( | )+([a-zA-Z])/g, '$1 $3') // 单词间保留一个空格 + .replace(/(\d)( | )+([a-zA-Z])/g, '$1 $3') // 数字和单词间 + .replace(/([a-zA-Z])( | )+(\d)/g, '$1 $3'); // 单词和数字间 + $el.html(html); + } + }); }); {/block} \ No newline at end of file