فهرست منبع

java的代码调整优化

liuchengsen 1 ماه پیش
والد
کامیت
3067ba9826
3فایلهای تغییر یافته به همراه8 افزوده شده و 3 حذف شده
  1. 4 1
      frontend-web/index.html
  2. 2 1
      miniprogram/components/ai-chat/index.vue
  3. 2 1
      miniprogram/pages/ai-yaodian/index.vue

+ 4 - 1
frontend-web/index.html

@@ -143,7 +143,10 @@ function escAttr(s){if(!s)return'';return s.replace(/"/g,'"').replace(/'/g,
 function md2html(h){if(!h)return'';h=esc(h);h=h.replace(/\*\*(.+?)\*\*/g,'<strong>$1</strong>');h=h.replace(/⚠️?\s*([^\n<]+)/g,'<span class="warn">$1</span>');
 // markdown 链接 [文字](url) → <a>
 h=h.replace(/\[([^\]]+)\]\((https?:\/\/[^\s<>)]+)\)/g,'<a href="$2" target="_blank" rel="noopener" class="ext-link">$1</a>');
-var s='(?:结论|详细说明|注意事项|来源明细|适应症|用法与用量|用法用量|禁忌|不良反应|副作用|药理|药物相互作用|贮藏|特殊人群|安全提醒|就医指征|非药物建议|用药建议|用药方案|通用药学知识|来源汇总|病情评估|处理方案|就医指征|免责声明|AI 声明|AI声明|来源说明|安全提醒)';h=h.replace(new RegExp('(?<![【])】\\s*('+s+')','g'),'【$1】');h=h.replace(new RegExp('(?<![【])('+s+')】','g'),'【$1】');h=h.replace(/(?<![<br>\n])【(.+?)】/g,'<br>【$1】');h=h.replace(/\n\n+/g,'</p><p>');h=h.replace(/\n/g,'<br>');h=h.replace(/【(.+?)】/g,'<h3>【$1】</h3>');h=h.replace(/(?:<br>|^)[-*•]\s+(.+?)(?=<br>|$)/g,'<li>$1</li>');h=h.replace(/((?:<li>.*?<\/li>)+)/g,'<ul>$1</ul>');h=h.replace(/(?:<br>|^)(\d+)\.\s+(.+?)(?=<br>|$)/g,'<li>$2</li>');h=h.replace(/((?:<li>.*?<\/li>)+)/g,function(m){return m.indexOf('<ul>')>=0?m:'<ol>'+m+'</ol>'});h='<p>'+h+'</p>';h=h.replace(/<p>(<br>)*<\/p>/g,'');h=h.replace(/<p><\/p>/g,'');
+var s='(?:结论|详细说明|注意事项|来源明细|适应症|用法与用量|用法用量|禁忌|不良反应|副作用|药理|药物相互作用|贮藏|特殊人群|安全提醒|就医指征|非药物建议|用药建议|用药方案|通用药学知识|来源汇总|病情评估|处理方案|就医指征|免责声明|AI 声明|AI声明|来源说明|安全提醒)';h=h.replace(new RegExp('(?<![【])】\\s*('+s+')','g'),'【$1】');h=h.replace(new RegExp('(?<![【])('+s+')】','g'),'【$1】');h=h.replace(/(?<![<br>\n])【(.+?)】/g,'<br>【$1】');h=h.replace(/\n\n+/g,'</p><p>');h=h.replace(/\n/g,'<br>');h=h.replace(/【(.+?)】/g,'<h3>【$1】</h3>');
+// 干掉 h3 后面紧跟的 <br>(避免 h3 margin + <br> = 多余空行)
+h=h.replace(/<\/h3><br>/g,'</h3>');
+h=h.replace(/(?:<br>|^)[-*•]\s+(.+?)(?=<br>|$)/g,'<li>$1</li>');h=h.replace(/((?:<li>.*?<\/li>)+)/g,'<ul>$1</ul>');h=h.replace(/(?:<br>|^)(\d+)\.\s+(.+?)(?=<br>|$)/g,'<li>$2</li>');h=h.replace(/((?:<li>.*?<\/li>)+)/g,function(m){return m.indexOf('<ul>')>=0?m:'<ol>'+m+'</ol>'});h='<p>'+h+'</p>';h=h.replace(/<p>(<br>)*<\/p>/g,'');h=h.replace(/<p><\/p>/g,'');
 // 纯 URL 自动转链接(宽松匹配,在 HTML 标签外)
 h=h.replace(/(?<!href=")(?<!href=')(?<!">)(?<!'>)(https?:\/\/[^\s<>]+)/g,'<a href="$1" target="_blank" rel="noopener" class="ext-link">$1</a>');
 return h}

+ 2 - 1
miniprogram/components/ai-chat/index.vue

@@ -110,7 +110,8 @@ export default {
       h = h.replace(new RegExp('(?<![【])(' + secs + ')】', 'g'), '【$1】')
       h = h.replace(/\n\n+/g, '</p><p>')
       h = h.replace(/\n/g, '<br>')
-      h = h.replace(/【(.+?)】/g, '<p style="font-size:30rpx;color:#002FA7;font-weight:bold;margin:16rpx 0 8rpx">【$1】</p>')
+      // 段落标题:吞掉紧跟的 <br>
+      h = h.replace(/【(.+?)】(?:<br>)?/g, '<p style="font-size:30rpx;color:#002FA7;font-weight:bold;margin:16rpx 0 4rpx">【$1】</p>')
       // markdown 链接 [文字](url) → <a>
       h = h.replace(/\[([^\]]+)\]\((https?:\/\/[^\s<>)]+)\)/g, '<a href="$2" style="color:#002FA7;text-decoration:underline">$1</a>')
       // 纯 URL 自动转可点击链接

+ 2 - 1
miniprogram/pages/ai-yaodian/index.vue

@@ -116,7 +116,8 @@ export default {
       h = h.replace(new RegExp('(?<![【])('+secs+')】','g'),'【$1】');
       h = h.replace(/\n\n+/g, '</p><p>')
       h = h.replace(/\n/g, '<br>')
-      h = h.replace(/【(.+?)】/g, '<p style="font-size:30rpx;color:#002FA7;font-weight:bold;margin:16rpx 0 8rpx">【$1】</p>')
+      // 段落标题:吞掉紧跟的 <br>(避免标题自带间距 + <br> = 多余空行)
+      h = h.replace(/【(.+?)】(?:<br>)?/g, '<p style="font-size:30rpx;color:#002FA7;font-weight:bold;margin:16rpx 0 4rpx">【$1】</p>')
       // markdown 链接 [文字](url) → <a>
       h = h.replace(/\[([^\]]+)\]\((https?:\/\/[^\s<>)]+)\)/g, '<a href="$2" style="color:#002FA7;text-decoration:underline">$1</a>')
       // 纯 URL 自动转可点击链接