فهرست منبع

前端显示优化

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

+ 2 - 1
frontend-web/index.html

@@ -144,7 +144,8 @@ function md2html(h){if(!h)return'';h=esc(h);h=h.replace(/\*\*(.+?)\*\*/g,'<stron
 // 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>');
-// 干掉 h3 后面紧跟的 <br>(避免 h3 margin + <br> = 多余空行)
+// 干掉 h3 前后的 <br>(h3 自带 margin,<br> 只会造成多余空行)
+h=h.replace(/<br><h3>/g,'<h3>');
 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 标签外)

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

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

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

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