Skip to content

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

feat: rename image_base64 field to _image_base64 across multiple modules and update related tests

myhlolia5423a2b734f
diff --git a/mineru/backend/analyze.py b/mineru/backend/analyze.py
index ae6d464c..cd8eb63b 100644
--- a/mineru/backend/analyze.py
+++ b/mineru/backend/analyze.py
@@ -1441,10 +1441,6 @@ def _attach_visual_block_images(
if not visual_blocks:
continue
- # 先清理模型可能携带的同名字段,保证最终载荷只来自当前 PDF 页面裁图。
- for _, block in visual_blocks:
- block.pop("image_base64", None)
-
page_index = page_start_index + page_offset
page_pil_image = image_dict.get("img_pil")
if page_pil_image is None:
@@ -1474,7 +1470,7 @@ def _attach_visual_block_images(
)
if not image_base64:
raise ValueError("empty crop or JPEG encoding failure")
- block["image_base64"] = image_base64
+ block["_image_base64"] = image_base64
except Exception as exc:
logger.warning(
"Skipping invalid model visual block crop: "
diff --git a/mineru/backend/office/office_magic_model.py b/mineru/backend/office/office_magic_model.py
index 5ead7251..5c8d8c93 100644
--- a/mineru/backend/office/office_magic_model.py
+++ b/mineru/backend/office/office_magic_model.py
@@ -59,8 +59,8 @@ class MagicModel:
bbox=EMPTY_BBOX,
content=image_cache.replace_html_data_uri_sources(block_content),
)
- if block_info.get("image_base64"):
- span.image_path = image_cache.register_data_uri(block_info["image_base64"])
+ if block_info.get("_image_base64"):
+ span.image_path = image_cache.register_data_uri(block_info["_image_base64"])
elif block_type in ["equation"]:
block_type = BlockType.INTERLINE_EQUATION
span = Span(type=ContentType.INTERLINE_EQUATION, bbox=EMPTY_BBOX, content=block_content)
diff --git a/mineru/model/flash/docx/docx_converter.py b/mineru/model/flash/docx/docx_converter.py
index e625346d..56be7562 100644
--- a/mineru/model/flash/docx/docx_converter.py
+++ b/mineru/model/flash/docx/docx_converter.py
@@ -1529,7 +1529,7 @@ class DocxConverter:
image_block = {
"type": BlockType.IMAGE,
- "image_base64": img_base64,
+ "_image_base64": img_base64,
}
self.cur_page.append(image_block)
diff --git a/mineru/model/flash/pptx/pptx_converter.py b/mineru/model/flash/pptx/pptx_converter.py
index 86924fcb..08b5bcca 100644
--- a/mineru/model/flash/pptx/pptx_converter.py
+++ b/mineru/model/flash/pptx/pptx_converter.py
@@ -719,7 +719,7 @@ class PptxConverter:
if content_type == "image/svg+xml":
image_block = {
"type": BlockType.IMAGE,
- "image_base64": self._bytes_to_data_uri(image_bytes, content_type),
+ "_image_base64": self._bytes_to_data_uri(image_bytes, content_type),
}
self.cur_page.append(image_block)
return
@@ -730,7 +730,7 @@ class PptxConverter:
image_block = {
"type": BlockType.IMAGE,
- "image_base64": img_base64,
+ "_image_base64": img_base64,
}
self.cur_page.append(image_block)
return
diff --git a/mineru/model/flash/xlsx/xlsx_converter.py b/mineru/model/flash/xlsx/xlsx_converter.py
index 3a232107..03cb0a44 100644
--- a/mineru/model/flash/xlsx/xlsx_converter.py
+++ b/mineru/model/flash/xlsx/xlsx_converter.py
@@ -988,7 +988,7 @@ class XlsxConverter:
self.cur_page.append(
{
"type": BlockType.IMAGE,
- "image_base64": image_info["base64"],
+ "_image_base64": image_info["base64"],
}
)
diff --git a/tests/unittest/test_flash_office_title_types.py b/tests/unittest/test_flash_office_title_types.py
index 1b78e314..d92a065d 100644
--- a/tests/unittest/test_flash_office_title_types.py
+++ b/tests/unittest/test_flash_office_title_types.py
@@ -53,8 +53,8 @@ def _set_subtitle(slide: Any, text: str) -> None:
subtitle.text = text
-def test_office_models_store_standalone_images_in_image_base64() -> None:
- """验证三类 Office model 的独立图片只通过 image_base64 输出。"""
+def test_office_models_store_standalone_images_in_private_image_base64() -> None:
+ """验证三类 Office model 的独立图片只通过 _image_base64 输出。"""
for suffix, model in (
("docx", DocxModel()),
("pptx", PptxModel()),
@@ -69,13 +69,13 @@ def test_office_models_store_standalone_images_in_image_base64() -> None:
assert image_blocks, suffix
for block in image_blocks:
assert "content" not in block
- assert isinstance(block.get("image_base64"), str)
- assert block["image_base64"].startswith("data:image/")
- assert ";base64," in block["image_base64"]
+ assert isinstance(block.get("_image_base64"), str)
+ assert block["_image_base64"].startswith("data:image/")
+ assert ";base64," in block["_image_base64"]
-def test_pptx_svg_picture_uses_image_base64(monkeypatch: Any) -> None:
- """验证 PPTX SVG 图片分支同样使用 image_base64 字段。"""
+def test_pptx_svg_picture_uses_private_image_base64(monkeypatch: Any) -> None:
+ """验证 PPTX SVG 图片分支同样使用 _image_base64 字段。"""
converter = PptxConverter()
def fake_get_shape_image_data(_shape: Any) -> tuple[bytes, str]:
@@ -89,7 +89,7 @@ def test_pptx_svg_picture_uses_image_base64(monkeypatch: Any) -> None:
assert converter.cur_page == [
{
"type": BlockType.IMAGE,
- "image_base64": "data:image/svg+xml;base64,PHN2Zy8+",
+ "_image_base64": "data:image/svg+xml;base64,PHN2Zy8+",
}
]