Browse Source

fix: 修复正则导致的某些svg显示问题

过卫栋 5 ngày trước cách đây
mục cha
commit
963898a94e
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      resources/views/components/exam/paper-body.blade.php

+ 4 - 2
resources/views/components/exam/paper-body.blade.php

@@ -123,7 +123,8 @@
             $cleanContent = trim($cleanContent);
             $options = $q->options ?? [];
             if (empty($options)) {
-                $pattern = '/([A-D])[\.、:.:]\s*(.+?)(?=\s*[A-D][\.、:.:]|$)/su';
+                // 【修复】选项标记必须在行首或空白后,避免误匹配 SVG 注释中的 BD:DC 等内容
+                $pattern = '/(?:^|\s)([A-D])[\.、:.:]\s*(.+?)(?=(?:^|\s)[A-D][\.、:.:]|$)/su';
                 if (preg_match_all($pattern, $cleanContent, $matches, PREG_SET_ORDER)) {
                     foreach ($matches as $match) {
                         $optionText = trim($match[2]);
@@ -135,7 +136,8 @@
             }
             $stemLine = $cleanContent;
             if (!empty($options)) {
-                if (preg_match('/^(.+?)(?=[A-D][\.、:.:])/su', $cleanContent, $stemMatch)) {
+                // 【修复】只匹配行首或空白后的选项标记,避免误匹配 SVG 注释中的 BD:DC 等内容
+                if (preg_match('/^(.+?)(?=(?:^|\s)[A-D][\.、:.:])/su', $cleanContent, $stemMatch)) {
                     $stemLine = trim($stemMatch[1]);
                 }
             }