Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

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

myhloli0f62f166e6a8
diff --git a/mineru/cli/gradio_app.py b/mineru/cli/gradio_app.py
index a7341550..a82f1909 100644
--- a/mineru/cli/gradio_app.py
+++ b/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)