Skip to content

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

feat: update image block structure to use image_base64 field instead of content

myhlolic6a46a5c1e46
diff --git a/mineru/model/flash/docx/docx_converter.py b/mineru/model/flash/docx/docx_converter.py
index 38f93a32..e625346d 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,
- "content": 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 33426eb5..86924fcb 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,
- "content": 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,
- "content": 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 7eee1394..3a232107 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,
- "content": 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 1881283e..1b78e314 100644
--- a/tests/unittest/test_flash_office_title_types.py
+++ b/tests/unittest/test_flash_office_title_types.py
@@ -53,6 +53,47 @@ 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 输出。"""
+ for suffix, model in (
+ ("docx", DocxModel()),
+ ("pptx", PptxModel()),
+ ("xlsx", XlsxModel()),
+ ):
+ image_blocks = [
+ block
+ for block in _flatten_pages(_predict_sample(model, suffix))
+ if block.get("type") == BlockType.IMAGE
+ ]
+
+ 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"]
+
+
+def test_pptx_svg_picture_uses_image_base64(monkeypatch: Any) -> None:
+ """验证 PPTX SVG 图片分支同样使用 image_base64 字段。"""
+ converter = PptxConverter()
+
+ def fake_get_shape_image_data(_shape: Any) -> tuple[bytes, str]:
+ """返回固定 SVG 图片载荷,隔离 PPTX shape 解析逻辑。"""
+ return b"<svg/>", "image/svg+xml"
+
+ monkeypatch.setattr(converter, "_get_shape_image_data", fake_get_shape_image_data)
+
+ converter._handle_pictures(object())
+
+ assert converter.cur_page == [
+ {
+ "type": BlockType.IMAGE,
+ "image_base64": "data:image/svg+xml;base64,PHN2Zy8+",
+ }
+ ]
+
+
def test_docx_model_splits_document_and_paragraph_titles() -> None:
"""验证 DOCX model 按样式来源拆分文档标题和段落标题。"""
pages = _predict_sample(DocxModel(), "docx")