Prechádzať zdrojové kódy

Enhance image link replacement to handle only .jpg files while preserving other formats

myhloli 1 mesiac pred
rodič
commit
0f62f166e6
1 zmenil súbory, kde vykonal 8 pridanie a 4 odobranie
  1. 8 4
      mineru/cli/gradio_app.py

+ 8 - 4
mineru/cli/gradio_app.py

@@ -86,10 +86,14 @@ def replace_image_with_base64(markdown_text, image_dir_path):
     # 替换图片链接
     def replace(match):
         relative_path = match.group(1)
-        full_path = os.path.join(image_dir_path, relative_path)
-        base64_image = image_to_base64(full_path)
-        return f'![{relative_path}](data:image/jpeg;base64,{base64_image})'
-
+        # 只处理以.jpg结尾的图片
+        if relative_path.endswith('.jpg'):
+            full_path = os.path.join(image_dir_path, relative_path)
+            base64_image = image_to_base64(full_path)
+            return f'![{relative_path}](data:image/jpeg;base64,{base64_image})'
+        else:
+            # 其他格式的图片保持原样
+            return match.group(0)
     # 应用替换
     return re.sub(pattern, replace, markdown_text)