Kaynağa Gözat

feat: 调整pdf里image标签图片的显示

过卫栋 4 hafta önce
ebeveyn
işleme
d0f952ca47

+ 17 - 0
app/Services/MathFormulaProcessor.php

@@ -26,6 +26,9 @@ class MathFormulaProcessor
         }
         $content = trim($content);
 
+        // 0.5 将自定义 <image> 标签转换为标准 <img> 标签
+        $content = self::convertImageTags($content);
+
         // 1. 【关键修复】处理公式内的双反斜杠 -> 单反斜杠
         // 数据库存储时 \sqrt 变成 \\sqrt,需要还原
         $content = self::normalizeBackslashesInDelimiters($content);
@@ -55,6 +58,20 @@ class MathFormulaProcessor
         }
     }
 
+    /**
+     * 将自定义 <image> 标签转换为标准 <img> 标签
+     * 例如:<image src="https://example.com/1.png"/> => <img src="https://example.com/1.png" />
+     */
+    private static function convertImageTags(string $content): string
+    {
+        // 匹配 <image src="..." /> 或 <image src="..."></image> 格式
+        return preg_replace(
+            '/<image\s+src=["\']([^"\']+)["\'](?:\s*\/>|><\/image>)/i',
+            '<img src="$1" />',
+            $content
+        );
+    }
+
     /**
      * 【新增】将公式定界符内的双反斜杠转为单反斜杠
      * 与前端 MathText.tsx 的 preprocessText 逻辑保持一致

+ 10 - 0
resources/views/pdf/exam-grading.blade.php

@@ -235,6 +235,16 @@
         svg circle, svg line, svg polygon, svg polyline {
             shape-rendering: geometricPrecision;
         }
+        /* 题干中的图片样式 */
+        .question-stem img,
+        .question-main img,
+        .question-content img {
+            display: block;
+            max-width: 100%;
+            height: auto;
+            margin: 12px auto;
+            box-sizing: border-box;
+        }
     </style>
 </head>
 <body style="page-break-before: always;">

+ 10 - 0
resources/views/pdf/exam-paper.blade.php

@@ -320,6 +320,16 @@
         .wavy-underline.short {
             min-width: 60px;
         }
+        /* 题干中的图片样式 */
+        .question-stem img,
+        .question-main img,
+        .question-content img {
+            display: block;
+            max-width: 100%;
+            height: auto;
+            margin: 12px auto;
+            box-sizing: border-box;
+        }
         @media print {
             .no-print {
                 display: none;