Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: replace 'RAW_TITLE' with '_VLM_UNCLASSIFIED_TITLE_TYPE' and update related logic across the codebase
myhloli839da4b0d949
diff --git a/mineru/backend/analyze.py b/mineru/backend/analyze.pyindex b656c323..49f97ed1 100644--- a/mineru/backend/analyze.py+++ b/mineru/backend/analyze.py@@ -39,7 +39,6 @@ from mineru.backend.utils.raw_block_types import (RAW_CAPTION,RAW_FOOTNOTE,RAW_PHONETIC,- RAW_TITLE,)from mineru.backend.utils.span_pre_proc import (SpanBlockMatcher,@@ -69,7 +68,7 @@ from mineru.utils.ocr_utils import (from mineru.utils.pdf_image_tools import load_images_from_pdf_bytes_range, get_crop_np_imgfrom tqdm import tqdm-from ..types import BBox, BlockType, ContentType, MiddleJson, NOT_EXTRACT_TYPES+from ..types import BBox, BlockType, ContentType, MiddleJsonfrom ..utils.config_reader import get_processing_window_sizefrom ..utils.pdf_document import PDFDocument, PDFPage, get_lines_from_chars@@ -94,8 +93,9 @@ _OFFICE_MODEL_MAP = {"xlsx": XlsxModel,}_SUPPORTED_FILE_SUFFIXES = {"pdf", *_OFFICE_MODEL_MAP}+_VLM_UNCLASSIFIED_TITLE_TYPE = "title"TITLE_BLOCK_TYPES = {- RAW_TITLE,+ _VLM_UNCLASSIFIED_TITLE_TYPE,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,}@@ -180,6 +180,25 @@ PIPELINE_DET_TYPE = {BlockType.REF_TEXT,RAW_FOOTNOTE,}+NOT_EXTRACT_TYPES = {+ BlockType.TEXT,+ _VLM_UNCLASSIFIED_TITLE_TYPE,+ BlockType.DOC_TITLE,+ BlockType.PARAGRAPH_TITLE,+ BlockType.HEADER,+ BlockType.FOOTER,+ BlockType.PAGE_NUMBER,+ BlockType.PAGE_FOOTNOTE,+ BlockType.REF_TEXT,+ BlockType.TABLE_CAPTION,+ BlockType.IMAGE_CAPTION,+ RAW_CAPTION,+ BlockType.TABLE_FOOTNOTE,+ BlockType.IMAGE_FOOTNOTE,+ RAW_FOOTNOTE,+ BlockType.CODE_CAPTION,+ RAW_PHONETIC,+}VLM_TXT_DET_TYPE = NOT_EXTRACT_TYPESVLM_OCR_DET_TYPE = {BlockType.TEXT,@@ -2439,7 +2458,7 @@ def _apply_layout_title_split(for page_model_list, layout_res, page_size in zip(model_list, images_layout_res, page_sizes):doc_title_bboxes = _collect_layout_doc_title_bboxes(layout_res, page_size)for block in page_model_list:- if block.get("type") != RAW_TITLE:+ if block.get("type") != _VLM_UNCLASSIFIED_TITLE_TYPE:continuetitle_bbox = _bbox_to_pixel_bbox(block.get("bbox"), page_size)if title_bbox is None:@@ -2498,7 +2517,7 @@ def _normalize_pdf_model_list(model_list: list[list[dict[str, Any]]]) -> None:if equation_content.endswith("\\]"):equation_content = equation_content[:-2]block["content"] = equation_content.strip()- elif raw_type == RAW_TITLE:+ elif raw_type == _VLM_UNCLASSIFIED_TITLE_TYPE:raise ValueError("Unclassified PDF title block: "f"page_idx={page_idx}, block_idx={block_idx}"diff --git a/mineru/backend/magic_model.py b/mineru/backend/magic_model.pyindex 0d1adb09..319bdc76 100644--- a/mineru/backend/magic_model.py+++ b/mineru/backend/magic_model.py@@ -7,20 +7,18 @@ from mineru.backend.utils.raw_block_types import (RAW_ALGORITHM,RAW_CAPTION,RAW_FOOTNOTE,- RAW_TITLE,)from mineru.backend.utils.visual_magic_model_utils import (code_content_clean,isolated_formula_clean,clean_content,- VISUAL_MAIN_TYPES,_bbox_for_calculation,regroup_visual_blocks,fallback_inline_caption_fragments,fallback_leading_table_continuation_captions,fallback_no_bbox_caption_fragments,)-from mineru.types import BlockType+from mineru.types import BlockType, VISUAL_MAIN_TYPESfrom mineru.utils.guess_suffix_or_lang import guess_language_by_text@@ -66,7 +64,7 @@ class MagicModel:if block_content:block_content = clean_content(block_content) or ""# 对于标题类块,去除换行符和多余空格- if block_type in [RAW_TITLE, BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE] and block_content:+ if block_type in [BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE] and block_content:block_content = re.sub(r"\n\s*", " ", block_content).strip()# 处理 code/algorithm 分类的特殊情况:如果 code 类型的块中包含成对的行内公式标记,则将其分类为 algorithm。if (diff --git a/mineru/backend/utils/para_block_utils.py b/mineru/backend/utils/para_block_utils.pyindex 5c8800f1..fe43d5b1 100644--- a/mineru/backend/utils/para_block_utils.py+++ b/mineru/backend/utils/para_block_utils.py@@ -7,7 +7,6 @@ from ...types import Block, BlockType, PageInfoLINE_STOP_FLAG = (".", "!", "?", "。", "!", "?", ")", ")", '"', "”", ":", ":", ";", ";")SECTION_MERGE_BARRIER_TYPES = {- BlockType.TITLE,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,BlockType.EQUATION,diff --git a/mineru/backend/utils/raw_block_types.py b/mineru/backend/utils/raw_block_types.pyindex fc286167..336379c2 100644--- a/mineru/backend/utils/raw_block_types.py+++ b/mineru/backend/utils/raw_block_types.py@@ -1,21 +1,24 @@# Copyright (c) Opendatalab. All rights reserved.from typing import Literal, TypeAlias-# 这些类型只允许存在于 Analyze/MagicModel 的 raw dict 阶段。+# 这些字符串不能作为公开 Block.type discriminator,只用于 raw 阶段或 Block 内部枚举值。RawBlockType: TypeAlias = Literal["algorithm","caption","footnote",- "title","phonetic",]RAW_ALGORITHM: RawBlockType = "algorithm"RAW_CAPTION: RawBlockType = "caption"RAW_FOOTNOTE: RawBlockType = "footnote"-RAW_TITLE: RawBlockType = "title"RAW_PHONETIC: RawBlockType = "phonetic"RAW_ONLY_BLOCK_TYPES = frozenset(- {RAW_ALGORITHM, RAW_CAPTION, RAW_FOOTNOTE, RAW_TITLE, RAW_PHONETIC}+ {+ RAW_ALGORITHM,+ RAW_CAPTION,+ RAW_FOOTNOTE,+ RAW_PHONETIC,+ })diff --git a/mineru/backend/utils/table_merge.py b/mineru/backend/utils/table_merge.pyindex 083f2909..3ce3b420 100644--- a/mineru/backend/utils/table_merge.py+++ b/mineru/backend/utils/table_merge.py@@ -21,9 +21,6 @@ TABLE_BOUNDARY_IGNORED_TYPES = {BlockType.PAGE_NUMBER,BlockType.PAGE_FOOTNOTE,BlockType.ASIDE_TEXT,- BlockType.HEADER_IMAGE,- BlockType.FOOTER_IMAGE,- BlockType.DISCARDED,}BlockDict: TypeAlias = dict[str, Any]diff --git a/mineru/backend/utils/visual_magic_model_utils.py b/mineru/backend/utils/visual_magic_model_utils.pyindex 277ac280..e1ef1f6a 100644--- a/mineru/backend/utils/visual_magic_model_utils.py+++ b/mineru/backend/utils/visual_magic_model_utils.py@@ -5,55 +5,23 @@ import refrom copy import deepcopyfrom typing import Any-from ...types import BBox, BlockType+from ...types import (+ BBox,+ BlockType,+ VISUAL_MAIN_TYPES,+ VISUAL_RELATION_IGNORED_TYPES,+ VISUAL_TYPE_MAPPING,+)from .boxbase import bbox_center_distance, bbox_distancefrom .raw_block_types import RAW_CAPTION, RAW_FOOTNOTEfrom .table_continuation import is_table_continuation_text-IMAGE_BLOCK_BODY = "image_block_body"-GENERIC_CHILD_TYPES = (RAW_CAPTION, RAW_FOOTNOTE)INLINE_CAPTION_FRAGMENT_TYPES = {BlockType.TEXT, RAW_FOOTNOTE}STACKED_TABLE_CAPTION_CLUSTER_TYPES = {RAW_CAPTION,BlockType.TEXT,RAW_FOOTNOTE,}-VISUAL_RELATION_IGNORED_TYPES = {- BlockType.HEADER,- BlockType.FOOTER,- BlockType.PAGE_NUMBER,- BlockType.PAGE_FOOTNOTE,- BlockType.ASIDE_TEXT,-}-VISUAL_MAIN_TYPES = {- BlockType.IMAGE_BODY: BlockType.IMAGE,- IMAGE_BLOCK_BODY: BlockType.IMAGE,- BlockType.TABLE_BODY: BlockType.TABLE,- BlockType.CHART_BODY: BlockType.CHART,- BlockType.CODE_BODY: BlockType.CODE,-}-VISUAL_TYPE_MAPPING = {- BlockType.IMAGE: {- "body": BlockType.IMAGE_BODY,- "caption": BlockType.IMAGE_CAPTION,- "footnote": BlockType.IMAGE_FOOTNOTE,- },- BlockType.TABLE: {- "body": BlockType.TABLE_BODY,- "caption": BlockType.TABLE_CAPTION,- "footnote": BlockType.TABLE_FOOTNOTE,- },- BlockType.CHART: {- "body": BlockType.CHART_BODY,- "caption": BlockType.CHART_CAPTION,- "footnote": BlockType.CHART_FOOTNOTE,- },- BlockType.CODE: {- "body": BlockType.CODE_BODY,- "caption": BlockType.CODE_CAPTION,- "footnote": BlockType.CODE_FOOTNOTE,- },-}VISUAL_CHILD_TYPE_MAPPING: dict[str, tuple[str | None, str]] = {RAW_CAPTION: (None, "caption"),RAW_FOOTNOTE: (None, "footnote"),diff --git a/mineru/model/flash/docx/docx_converter.py b/mineru/model/flash/docx/docx_converter.pyindex e625346d..464e169f 100644--- a/mineru/model/flash/docx/docx_converter.py+++ b/mineru/model/flash/docx/docx_converter.py@@ -21,6 +21,7 @@ from mineru.backend.utils.office_chart import extract_chart_html_from_ooxmlfrom mineru.backend.utils.office_image import (serialize_office_image,)+from mineru.backend.utils.raw_block_types import RAW_CAPTIONfrom mineru.model.flash.docx.package_normalizer import normalize_docx_packagefrom mineru.model.flash.docx.tools.math.omml import oMath2Latexfrom mineru.model.flash.docx.tools.office_xml import read_str@@ -1450,7 +1451,7 @@ class DocxConverter:content_text = self._build_text_with_equations_and_hyperlinks(paragraph_elements, text, equations)if content_text != "":caption_block = {- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"content": content_text,}self.cur_page.append(caption_block)diff --git a/mineru/model/flash/pptx/pptx_converter.py b/mineru/model/flash/pptx/pptx_converter.pyindex 86924fcb..bc2ac73f 100644--- a/mineru/model/flash/pptx/pptx_converter.py+++ b/mineru/model/flash/pptx/pptx_converter.py@@ -41,6 +41,7 @@ A14_DRAWING_NS: Final = "http://schemas.microsoft.com/office/drawing/2010/main"OMML_NS: Final = "http://schemas.openxmlformats.org/officeDocument/2006/math"_EFFECTIVE_FONT_SIZE_KEY: Final = "_effective_font_size_pt"_EFFECTIVE_ALL_BOLD_KEY: Final = "_effective_all_bold"+_PPTX_TITLE_CANDIDATE_KEY: Final = "_pptx_title_candidate"# PPTX 标题占位符角色仅用于单页内部归一化,返回 model_output 前必须清理。_PPTX_TITLE_ROLE_KEY: Final = "_pptx_title_role"_PPTX_TITLE_ROLE_CENTER: Final = "center_title"@@ -1675,6 +1676,7 @@ class PptxConverter:for block in slide_blocksif (block.get("type") == BlockType.TEXT+ and block.get(_PPTX_TITLE_CANDIDATE_KEY) is not Trueand block.get(_EFFECTIVE_FONT_SIZE_KEY) is not Noneand not block.get(_EFFECTIVE_ALL_BOLD_KEY, False))@@ -1694,6 +1696,7 @@ class PptxConverter:for block in slide_blocksif (block.get("type") == BlockType.TEXT+ and block.get(_PPTX_TITLE_CANDIDATE_KEY) is not Trueand block.get(_EFFECTIVE_ALL_BOLD_KEY, False)and block.get(_EFFECTIVE_FONT_SIZE_KEY) is not None)@@ -1717,7 +1720,7 @@ class PptxConverter:if len(bold_font_sizes) > 1 and level2_font_size_pt < bold_font_sizes[1] + 2:return- level2_candidates[0]["type"] = BlockType.TITLE+ level2_candidates[0][_PPTX_TITLE_CANDIDATE_KEY] = Truelevel2_candidates[0]["level"] = 2def _promote_level3_text_blocks(@@ -1733,7 +1736,7 @@ class PptxConverter:block[_EFFECTIVE_FONT_SIZE_KEY]for block in slide_blocksif (- block.get("type") == BlockType.TITLE+ block.get(_PPTX_TITLE_CANDIDATE_KEY) is Trueand block.get("level") == 2and block.get(_EFFECTIVE_FONT_SIZE_KEY) is not None)@@ -1750,6 +1753,7 @@ class PptxConverter:for block in slide_blocksif (block.get("type") == BlockType.TEXT+ and block.get(_PPTX_TITLE_CANDIDATE_KEY) is not Trueand block.get(_EFFECTIVE_ALL_BOLD_KEY, False)and block.get(_EFFECTIVE_FONT_SIZE_KEY) is not Noneand block[_EFFECTIVE_FONT_SIZE_KEY] < level2_font_size_pt@@ -1769,10 +1773,11 @@ class PptxConverter:for block in slide_blocks:if (block.get("type") == BlockType.TEXT+ and block.get(_PPTX_TITLE_CANDIDATE_KEY) is not Trueand block.get(_EFFECTIVE_ALL_BOLD_KEY, False)and block.get(_EFFECTIVE_FONT_SIZE_KEY) == level3_font_size_pt):- block["type"] = BlockType.TITLE+ block[_PPTX_TITLE_CANDIDATE_KEY] = Trueblock["level"] = 3@staticmethod@@ -1781,18 +1786,18 @@ class PptxConverter:*,is_first_visible_slide: bool,) -> None:- """将 PPTX 内部 title 统一拆分为文档标题、段落标题或普通文本。"""+ """将 PPTX 标题候选统一拆分为文档标题、段落标题或普通文本。"""for block in slide_blocks:+ is_title_candidate = block.pop(_PPTX_TITLE_CANDIDATE_KEY, False) is Truetitle_role = block.pop(_PPTX_TITLE_ROLE_KEY, None)+ if not is_title_candidate:+ continueif title_role == _PPTX_TITLE_ROLE_SUBTITLE:block["type"] = BlockType.TEXTblock.pop("level", None)block.pop("is_numbered_style", None)continue- if block.get("type") != BlockType.TITLE:- continue-if title_role == _PPTX_TITLE_ROLE_CENTER and is_first_visible_slide:block["type"] = BlockType.DOC_TITLEblock.pop("level", None)@@ -1805,6 +1810,7 @@ class PptxConverter:for block in slide_blocks:block.pop(_EFFECTIVE_FONT_SIZE_KEY, None)block.pop(_EFFECTIVE_ALL_BOLD_KEY, None)+ block.pop(_PPTX_TITLE_CANDIDATE_KEY, None)block.pop(_PPTX_TITLE_ROLE_KEY, None)def _handle_text_elements(self, shape):@@ -1853,7 +1859,7 @@ class PptxConverter:placeholder_type = shape.placeholder_format.typetitle_role = _PPTX_TITLE_PLACEHOLDER_ROLES.get(placeholder_type)if title_role is not None:- block["type"] = BlockType.TITLE+ block[_PPTX_TITLE_CANDIDATE_KEY] = Trueblock["level"] = 2block[_PPTX_TITLE_ROLE_KEY] = title_rolediff --git a/mineru/render/content_list.py b/mineru/render/content_list.pyindex bfd0f40d..50a0a3bd 100644--- a/mineru/render/content_list.py+++ b/mineru/render/content_list.py@@ -1,6 +1,7 @@# Copyright (c) Opendatalab. All rights reserved.from __future__ import annotations+from ..backend.utils.raw_block_types import RAW_PHONETICfrom ..types import EMPTY_BBOX, BBox, Block, BlockType, ContentItem, ContentType, IntBBoxfrom .markdown import _build_media_path, _get_title_levelfrom .merge import _merge_para_text, merge_para_text@@ -16,7 +17,7 @@ def block_to_content_list(para_type = para_block.typeif para_type in [BlockType.TEXT,- BlockType.PHONETIC,+ RAW_PHONETIC,BlockType.HEADER,BlockType.FOOTER,BlockType.PAGE_NUMBER,@@ -27,7 +28,7 @@ def block_to_content_list(type=para_type,text=merge_para_text(para_block),)- elif para_type in [BlockType.INDEX, BlockType.ABSTRACT]:+ elif para_type == BlockType.INDEX:item = ContentItem(type=ContentType.TEXT,text=merge_para_text(para_block),@@ -55,7 +56,7 @@ def block_to_content_list(type=para_type,text=merge_para_text(para_block),)- elif para_type == BlockType.TITLE:+ elif para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = _get_title_level(para_block)item = ContentItem(type=ContentType.TEXT,diff --git a/mineru/render/markdown.py b/mineru/render/markdown.pyindex b9112c34..0b3392c1 100644--- a/mineru/render/markdown.py+++ b/mineru/render/markdown.py@@ -1,3 +1,4 @@+from ..backend.utils.raw_block_types import RAW_PHONETICfrom ..types import Block, BlockType, ContentTypefrom .markdown_table import to_markdown_tablefrom .merge import merge_para_text@@ -38,18 +39,16 @@ def _block_to_markdown(para_type = para_block.typeif para_type == BlockType.TEXT:return merge_para_text(para_block)- if para_type == BlockType.TITLE:+ if para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = _get_title_level(para_block)return f"{'#' * title_level} {merge_para_text(para_block)}"if para_type == BlockType.INDEX:return merge_para_text(para_block)- if para_type == BlockType.ABSTRACT:- return merge_para_text(para_block)if para_type == BlockType.REF_TEXT:return merge_para_text(para_block)if para_type == BlockType.LIST:return merge_para_text(para_block)- if para_type == BlockType.PHONETIC:+ if para_type == RAW_PHONETIC:return merge_para_text(para_block)if para_type == BlockType.CODE:return merge_visual_para_text(para_block)@@ -76,7 +75,7 @@ def _block_to_markdown(def _get_title_level(block: Block) -> int:- title_level = block.level+ title_level = getattr(block, "level", None)if title_level is None:title_level = 1if title_level > 6:diff --git a/mineru/render/merge_visual.py b/mineru/render/merge_visual.pyindex b0f4e3bb..49241bfd 100644--- a/mineru/render/merge_visual.py+++ b/mineru/render/merge_visual.py@@ -5,6 +5,7 @@ from copy import deepcopyfrom html import escape, unescapefrom typing import Any+from ..backend.utils.raw_block_types import RAW_ALGORITHMfrom ..types import Block, BlockType, ContentTypefrom .merge import inline_left, inline_right, merge_para_text@@ -173,7 +174,7 @@ def _render_visual_block_segments(block: Block, para_block: Block, img_bucket_pablock_type = block.type- if block_type == BlockType.CODE_BODY and block.sub_type == BlockType.ALGORITHM:+ if block_type == BlockType.CODE_BODY and block.sub_type == RAW_ALGORITHM:text = _render_algorithm_code_html(block)if text:return [(text, "html_block")]diff --git a/mineru/render/office/merge.py b/mineru/render/office/merge.pyindex e024b723..1da49edc 100644--- a/mineru/render/office/merge.py+++ b/mineru/render/office/merge.py@@ -140,7 +140,7 @@ def _escape_office_inline_text(content: str, inline_syntax: str) -> str:def get_title_level(para_block: Block) -> int:- title_level = para_block.level+ title_level = getattr(para_block, "level", None)if title_level is None:title_level = 2return title_level@@ -506,7 +506,7 @@ def _hyperlink_requires_html(span: Span) -> bool:def _iter_block_inline_units(para_block: Block) -> Generator[dict[str, Any], None, None]:"""把 block 展开为线性文本单元,用于判断 Markdown 边界风险。"""- if para_block.type == BlockType.TITLE:+ if para_block.type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:section_number = para_block.section_numberif para_block.is_numbered_style and section_number:yield {@@ -881,7 +881,7 @@ def merge_para_with_text(para_block: Block, escape_text_block_prefix: bool = Tru_append_style_grouped_text_parts(parts, text_span_buffer, inline_syntax)text_span_buffer.clear()- if para_block.type == BlockType.TITLE:+ if para_block.type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:if para_block.is_numbered_style:section_number = para_block.section_numberif section_number:diff --git a/mineru/render/office/output.py b/mineru/render/office/output.pyindex df731577..18f4fb23 100644--- a/mineru/render/office/output.py+++ b/mineru/render/office/output.py@@ -376,7 +376,7 @@ def blocks_to_markdown(para_text = merge_list_to_markdown(para_block)elif para_type == BlockType.INDEX:para_text = merge_index_to_markdown(para_block)- elif para_type == BlockType.TITLE:+ elif para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = get_title_level(para_block)title_text = merge_para_with_text(para_block)bookmark_anchor = para_block.anchor@@ -446,7 +446,7 @@ def make_blocks_to_content_list(para_block: Block, img_bucket_path: str, page_id"type": para_type,"list_items": _flatten_index_items(para_block),}- elif para_type == BlockType.TITLE:+ elif para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = get_title_level(para_block)para_content = {"type": ContentType.TEXT,@@ -524,7 +524,7 @@ def block_to_structured_content(para_block: Block, img_bucket_path: str) -> dictf"{content_type}_content": merge_para_with_structured_spans(para_block),},}- elif para_type == BlockType.TITLE:+ elif para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = get_title_level(para_block)if title_level != 0:para_content = {@@ -714,7 +714,7 @@ def merge_para_with_structured_spans(para_block: Block) -> list[dict[str, Any]]:"""将 Office 段落转换为 structured_content spans,避免原地修改 middle_json。"""_visible_styles = {"underline", "strikethrough"}para_content: list[dict[str, Any]] = []- if para_block.type == BlockType.TITLE:+ if para_block.type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:section_number = para_block.section_numberif section_number:# structured_content 保持结构化 spans,同时补上 middle_json 已生成的自动标题编号。diff --git a/mineru/render/structured_content.py b/mineru/render/structured_content.pyindex ef0e822d..825da4f6 100644--- a/mineru/render/structured_content.py+++ b/mineru/render/structured_content.py@@ -4,6 +4,7 @@ from __future__ import annotationsfrom typing import Anyfrom ..backend.utils.char_utils import CJK_LANGS, resolve_text_line_boundary+from ..backend.utils.raw_block_types import RAW_ALGORITHM, RAW_PHONETICfrom ..types import BBox, Block, BlockType, ContentType, ContentTypeV2, IntBBox, Linefrom ..utils.language import detect_langfrom .markdown import _get_title_level@@ -73,7 +74,7 @@ def block_to_structured_content(f"{content_type}_content": merge_para_with_structured_spans(para_block),},}- elif para_type == BlockType.TITLE:+ elif para_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:title_level = _get_title_level(para_block)if title_level != 0:para_content = {@@ -85,7 +86,7 @@ def block_to_structured_content(}else:para_content = _paragraph_content(para_block)- elif para_type in [BlockType.TEXT, BlockType.ABSTRACT, BlockType.PHONETIC]:+ elif para_type in [BlockType.TEXT, RAW_PHONETIC]:para_content = _paragraph_content(para_block)elif para_type == BlockType.EQUATION:image_path, math_content = _get_body_data(para_block)@@ -136,7 +137,7 @@ def merge_para_with_structured_spans(para_block: Block) -> list[dict[str, Any]]:if not content.strip():continue- output_type = ContentTypeV2.SPAN_PHONETIC if para_type == BlockType.PHONETIC else ContentTypeV2.SPAN_TEXT+ output_type = ContentTypeV2.SPAN_PHONETIC if para_type == RAW_PHONETIC else ContentTypeV2.SPAN_TEXTrendered_content = _render_text_span_content(para_block,block_lang,@@ -300,7 +301,7 @@ def _code_content(para_block: Block) -> dict[str, Any]:"code_language": para_block.guess_lang or "txt",},}- if sub_type == BlockType.ALGORITHM:+ if sub_type == RAW_ALGORITHM:return {"type": ContentTypeV2.ALGORITHM,"content": {diff --git a/mineru/types.py b/mineru/types.pyindex 07964f97..43a624b6 100644--- a/mineru/types.py+++ b/mineru/types.py@@ -11,6 +11,8 @@ from typing import Annotated, Any, ClassVar, Literal, TypeAlias, Unionfrom pydantic import BaseModel, ConfigDict, Field, TypeAdapter, field_validator, model_validator+from .backend.utils.raw_block_types import RAW_ALGORITHM+Tier = Literal["flash","medium",@@ -63,20 +65,13 @@ class BlockType:CODE_CAPTION = "code_caption"CODE_FOOTNOTE = "code_footnote"- CAPTION = "caption" # generic caption type (e.g., for Word documents)- ALGORITHM_CAPTION = "algorithm_caption"- FOOTNOTE = "footnote" # pp_layout中的vision_footnoteTEXT = "text"- TITLE = "title"EQUATION = "equation" # 行间公式(独立公式)LIST = "list"INDEX = "index"- DISCARDED = "discarded"# Added in vlm 2.5- ALGORITHM = "algorithm"REF_TEXT = "ref_text"- PHONETIC = "phonetic"HEADER = "header"FOOTER = "footer"PAGE_NUMBER = "page_number"@@ -84,12 +79,8 @@ class BlockType:PAGE_FOOTNOTE = "page_footnote"# Added in pp_doclayout_v2- ABSTRACT = "abstract"DOC_TITLE = "doc_title"PARAGRAPH_TITLE = "paragraph_title"- VERTICAL_TEXT = "vertical_text"- HEADER_IMAGE = "header_image"- FOOTER_IMAGE = "footer_image"FORMULA_NUMBER = "formula_number"@@ -195,55 +186,6 @@ BLOCK_TYPES = {BlockType.FORMULA_NUMBER,}-NOT_EXTRACT_TYPES = {- BlockType.TEXT,- BlockType.TITLE,- BlockType.DOC_TITLE,- BlockType.PARAGRAPH_TITLE,- BlockType.HEADER,- BlockType.FOOTER,- BlockType.PAGE_NUMBER,- BlockType.PAGE_FOOTNOTE,- BlockType.REF_TEXT,- BlockType.TABLE_CAPTION,- BlockType.IMAGE_CAPTION,- BlockType.CAPTION,- BlockType.TABLE_FOOTNOTE,- BlockType.IMAGE_FOOTNOTE,- BlockType.FOOTNOTE,- BlockType.CODE_CAPTION,- BlockType.PHONETIC,-}---# 文本类 block 共用 text bbox 样式,避免新增文本形态时遗漏多个绘制入口。-TEXT_LIKE_BLOCK_TYPES_FOR_BBOX = {- BlockType.TEXT,- BlockType.REF_TEXT,- BlockType.ABSTRACT,- BlockType.PHONETIC,-}--# layout.pdf 中这些 block 直接使用自身 bbox,复合 block 则使用子 block bbox。-DIRECT_LAYOUT_BBOX_BLOCK_TYPES = TEXT_LIKE_BLOCK_TYPES_FOR_BBOX | {- BlockType.TITLE,- BlockType.EQUATION,- BlockType.LIST,- BlockType.INDEX,-}--# span.pdf 从这些结构性 block 中收集内部 span bbox。-SPAN_SOURCE_BLOCK_TYPES = DIRECT_LAYOUT_BBOX_BLOCK_TYPES---IMAGE_BLOCK_BODY = "image_block_body"-GENERIC_CHILD_TYPES = (BlockType.CAPTION, BlockType.FOOTNOTE)-INLINE_CAPTION_FRAGMENT_TYPES = {BlockType.TEXT, BlockType.FOOTNOTE}-STACKED_TABLE_CAPTION_CLUSTER_TYPES = {- BlockType.CAPTION,- BlockType.TEXT,- BlockType.FOOTNOTE,-}VISUAL_RELATION_IGNORED_TYPES = {BlockType.HEADER,BlockType.FOOTER,@@ -253,7 +195,6 @@ VISUAL_RELATION_IGNORED_TYPES = {}VISUAL_MAIN_TYPES = {BlockType.IMAGE_BODY: BlockType.IMAGE,- IMAGE_BLOCK_BODY: BlockType.IMAGE,BlockType.TABLE_BODY: BlockType.TABLE,BlockType.CHART_BODY: BlockType.CHART,BlockType.CODE_BODY: BlockType.CODE,@@ -280,8 +221,6 @@ VISUAL_TYPE_MAPPING = {"footnote": BlockType.CODE_FOOTNOTE,},}--# ── model types ─────────────────────────────────────────────────────BBox: TypeAlias = tuple[float, float, float, float]@@ -611,7 +550,7 @@ CodeChildBlock: TypeAlias = Annotated[class CodeBlock(_VisualBlockBase):type: Literal[BlockType.CODE]content: list[CodeChildBlock]- sub_type: Literal[BlockType.CODE, BlockType.ALGORITHM]+ sub_type: Literal[BlockType.CODE, RAW_ALGORITHM]guess_lang: str | None = None_body_type: ClassVar[str] = BlockType.CODE_BODYdiff --git a/mineru/utils/draw_bbox.py b/mineru/utils/draw_bbox.pyindex 704a4ebe..fe2e7b34 100644--- a/mineru/utils/draw_bbox.py+++ b/mineru/utils/draw_bbox.py@@ -9,19 +9,20 @@ from loguru import loggerfrom pypdf import PageObject, PdfReader, PdfWriterfrom reportlab.pdfgen import canvas+from ..backend.utils.raw_block_types import RAW_PHONETICfrom ..types import BBox, Block, BlockType, ContentType, PageInfo, Span# 文本类 block 共用 text bbox 样式,避免新增文本形态时遗漏多个绘制入口。TEXT_LIKE_BLOCK_TYPES_FOR_BBOX = {BlockType.TEXT,BlockType.REF_TEXT,- BlockType.ABSTRACT,- BlockType.PHONETIC,+ RAW_PHONETIC,}# layout.pdf 中这些 block 直接使用自身 bbox,复合 block 则使用子 block bbox。DIRECT_LAYOUT_BBOX_BLOCK_TYPES = TEXT_LIKE_BLOCK_TYPES_FOR_BBOX | {- BlockType.TITLE,+ BlockType.DOC_TITLE,+ BlockType.PARAGRAPH_TITLE,BlockType.EQUATION,BlockType.LIST,BlockType.INDEX,@@ -236,7 +237,7 @@ def draw_layout_bbox(elif nested_block.type == BlockType.CHART_FOOTNOTE:bbox = nested_block.bboximgs_footnote.append(bbox)- elif block.type == BlockType.TITLE:+ elif block.type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:titles.append(bbox)elif block.type in TEXT_LIKE_BLOCK_TYPES_FOR_BBOX:texts.append(bbox)diff --git a/mineru/utils/llm_aided.py b/mineru/utils/llm_aided.pyindex acbb00b1..85b7973b 100644--- a/mineru/utils/llm_aided.py+++ b/mineru/utils/llm_aided.py@@ -13,7 +13,6 @@ from ..render.merge import merge_para_textfrom ..types import BBox, Block, BlockType, PageInfoTITLE_BLOCK_TYPES = {- BlockType.TITLE,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,}@@ -229,12 +228,6 @@ def _apply_levels_to_blocks(title_block_refs: list[tuple[PageInfo, Block]], leveblock.level = int(levels_by_index[i])-def _normalize_title_types(title_block_refs: list[tuple[PageInfo, Block]]) -> None:- for _, block in title_block_refs:- if block.type in [BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE]:- block.type = BlockType.TITLE--def _get_title_block_identity(block: Block) -> tuple[str, int] | tuple[str, BBox, str]:block_index = block.indexif block_index is not None:@@ -262,8 +255,9 @@ def _sync_para_titles_to_preproc(page_info_list: list[PageInfo]) -> None:continueblock.type = para_block.type- if para_block.level is not None:- block.level = para_block.level+ para_level = getattr(para_block, "level", None)+ if para_level is not None:+ block.level = para_leveldef _run_single_pass_title_leveling(title_block_refs: list[tuple[PageInfo, Block]], title_aided_config: dict[str, Any]) -> None:@@ -313,13 +307,6 @@ def _request_paragraph_group_levels(def _run_grouped_title_leveling(title_block_refs: list[tuple[PageInfo, Block]], title_aided_config: dict[str, Any]) -> None:- doc_title_refs = []- for title_ref in title_block_refs:- _, block = title_ref- if block.type == BlockType.DOC_TITLE:- block.level = 1- doc_title_refs.append(title_ref)-paragraph_title_groups = _split_paragraph_title_groups(title_block_refs)group_levels = []@@ -343,10 +330,6 @@ def _run_grouped_title_leveling(title_block_refs: list[tuple[PageInfo, Block]],for title_group, levels_by_index in zip(paragraph_title_groups, group_levels):_apply_levels_to_blocks(title_group, levels_by_index)- _normalize_title_types(doc_title_refs)- for title_group in paragraph_title_groups:- _normalize_title_types(title_group)-def llm_aided_title(page_info_list: list[PageInfo], title_aided_config: dict[str, Any]) -> None:title_block_refs, title_types = _collect_title_block_refs(page_info_list)@@ -356,26 +339,18 @@ def llm_aided_title(page_info_list: list[PageInfo], title_aided_config: dict[strhas_doc_title = BlockType.DOC_TITLE in title_typeshas_paragraph_title = BlockType.PARAGRAPH_TITLE in title_types- has_generic_title = BlockType.TITLE in title_types-- if has_doc_title and has_paragraph_title and not has_generic_title:+ if has_doc_title and has_paragraph_title:_run_grouped_title_leveling(title_block_refs, title_aided_config)_sync_para_titles_to_preproc(page_info_list)return- doc_title_refs = []title_refs_for_llm = []for title_ref in title_block_refs:_, block = title_ref- if block.type == BlockType.DOC_TITLE:- block.level = 1- doc_title_refs.append(title_ref)- else:+ if block.type != BlockType.DOC_TITLE:title_refs_for_llm.append(title_ref)if len(title_refs_for_llm) > 0:_run_single_pass_title_leveling(title_refs_for_llm, title_aided_config)- _normalize_title_types(doc_title_refs)- _normalize_title_types(title_refs_for_llm)_sync_para_titles_to_preproc(page_info_list)diff --git a/tests/unittest/test_flash_office_title_types.py b/tests/unittest/test_flash_office_title_types.pyindex cf09315e..defb8684 100644--- a/tests/unittest/test_flash_office_title_types.py+++ b/tests/unittest/test_flash_office_title_types.py@@ -10,6 +10,9 @@ from pptx.enum.shapes import PP_PLACEHOLDERfrom mineru.model.flash import DocxModel, PptxModel, XlsxModelfrom mineru.model.flash.pptx.pptx_converter import (PptxConverter,+ _EFFECTIVE_ALL_BOLD_KEY,+ _EFFECTIVE_FONT_SIZE_KEY,+ _PPTX_TITLE_CANDIDATE_KEY,_PPTX_TITLE_ROLE_CENTER,_PPTX_TITLE_ROLE_KEY,_PPTX_TITLE_ROLE_SUBTITLE,@@ -99,7 +102,6 @@ def test_docx_model_splits_document_and_paragraph_titles() -> None:pages = _predict_sample(DocxModel(), "docx")blocks = _flatten_pages(pages)- assert all(block.get("type") != BlockType.TITLE for block in blocks)assert pages[0][0]["content"] == "MinerU supports DOCX document parsing now"doc_title = _find_block_by_content(blocks, "MinerU supports DOCX document parsing now")@@ -124,7 +126,7 @@ def test_pptx_model_splits_title_placeholders_and_subtitle() -> None:pages = _predict_sample(PptxModel(), "pptx")blocks = _flatten_pages(pages)- assert all(block.get("type") != BlockType.TITLE for block in blocks)+ assert all(_PPTX_TITLE_CANDIDATE_KEY not in block for block in blocks)assert all(_PPTX_TITLE_ROLE_KEY not in block for block in blocks)assert [block["content"] for block in pages[0] if block.get("content") in {"Test Table Slide", "With footnote"}] == ["Test Table Slide",@@ -146,32 +148,36 @@ def test_pptx_model_splits_title_placeholders_and_subtitle() -> None:assert slide_title["level"] == 2-def test_pptx_internal_titles_are_finalized_without_losing_levels() -> None:- """验证 PPTX 内部 title 收口时清理文档标题字段并保留段落标题层级。"""+def test_pptx_title_candidates_are_finalized_without_losing_levels() -> None:+ """验证 PPTX 标题候选收口时清理内部标记并保留段落标题层级。"""blocks = [{- "type": BlockType.TITLE,+ "type": BlockType.TEXT,"content": "document","level": 2,"is_numbered_style": False,+ _PPTX_TITLE_CANDIDATE_KEY: True,_PPTX_TITLE_ROLE_KEY: _PPTX_TITLE_ROLE_CENTER,},{- "type": BlockType.TITLE,+ "type": BlockType.TEXT,"content": "subtitle","level": 2,+ _PPTX_TITLE_CANDIDATE_KEY: True,_PPTX_TITLE_ROLE_KEY: _PPTX_TITLE_ROLE_SUBTITLE,},{- "type": BlockType.TITLE,+ "type": BlockType.TEXT,"content": "slide title","level": 2,+ _PPTX_TITLE_CANDIDATE_KEY: True,_PPTX_TITLE_ROLE_KEY: _PPTX_TITLE_ROLE_TITLE,},{- "type": BlockType.TITLE,+ "type": BlockType.TEXT,"content": "promoted title","level": 3,+ _PPTX_TITLE_CANDIDATE_KEY: True,},]@@ -188,13 +194,15 @@ def test_pptx_internal_titles_are_finalized_without_losing_levels() -> None:assert "level" not in blocks[1]assert blocks[2]["level"] == 2assert blocks[3]["level"] == 3+ assert all(_PPTX_TITLE_CANDIDATE_KEY not in block for block in blocks)assert all(_PPTX_TITLE_ROLE_KEY not in block for block in blocks)later_center_title = [{- "type": BlockType.TITLE,+ "type": BlockType.TEXT,"content": "later center title","level": 2,+ _PPTX_TITLE_CANDIDATE_KEY: True,_PPTX_TITLE_ROLE_KEY: _PPTX_TITLE_ROLE_CENTER,}]@@ -206,6 +214,38 @@ def test_pptx_internal_titles_are_finalized_without_losing_levels() -> None:assert later_center_title[0]["level"] == 2+def test_pptx_existing_title_candidates_do_not_participate_in_text_promotion() -> None:+ """验证占位符标题候选不会干扰普通文本的字号标题提升。"""+ blocks = [+ {+ "type": BlockType.TEXT,+ "content": "placeholder title",+ _PPTX_TITLE_CANDIDATE_KEY: True,+ _PPTX_TITLE_ROLE_KEY: _PPTX_TITLE_ROLE_CENTER,+ _EFFECTIVE_FONT_SIZE_KEY: 48.0,+ _EFFECTIVE_ALL_BOLD_KEY: True,+ },+ {+ "type": BlockType.TEXT,+ "content": "body",+ _EFFECTIVE_FONT_SIZE_KEY: 10.0,+ _EFFECTIVE_ALL_BOLD_KEY: False,+ },+ {+ "type": BlockType.TEXT,+ "content": "promoted section",+ _EFFECTIVE_FONT_SIZE_KEY: 20.0,+ _EFFECTIVE_ALL_BOLD_KEY: True,+ },+ ]++ PptxConverter()._promote_slide_text_blocks_to_titles(blocks)++ assert blocks[0][_PPTX_TITLE_CANDIDATE_KEY] is True+ assert blocks[2][_PPTX_TITLE_CANDIDATE_KEY] is True+ assert blocks[2]["level"] == 2++def test_pptx_notes_only_slide_does_not_consume_document_title() -> None:"""验证空白且仅含备注的前置页不会抢占首个可见文档标题。"""presentation = Presentation()@@ -231,7 +271,7 @@ def test_pptx_notes_only_slide_does_not_consume_document_title() -> None:later_title = _find_block_by_content(blocks, "Section cover")assert later_title["type"] == BlockType.PARAGRAPH_TITLEassert later_title["level"] == 2- assert all(block.get("type") != BlockType.TITLE for block in blocks)+ assert all(_PPTX_TITLE_CANDIDATE_KEY not in block for block in blocks)def test_xlsx_model_emits_sheet_names_as_paragraph_titles() -> None:@@ -243,4 +283,4 @@ def test_xlsx_model_emits_sheet_names_as_paragraph_titles() -> None:assert [page[0]["content"] for page in pages] == ["Sheet1", "Sheet2", "Sheet3"]assert all(block["type"] == BlockType.PARAGRAPH_TITLE for block in sheet_titles)assert all("level" not in block for block in sheet_titles)- assert all(block.get("type") not in {BlockType.TITLE, BlockType.DOC_TITLE} for block in blocks)+ assert all(block.get("type") != BlockType.DOC_TITLE for block in blocks)diff --git a/tests/unittest/test_middle_json_block_models.py b/tests/unittest/test_middle_json_block_models.pyindex ec8edad6..41a3272a 100644--- a/tests/unittest/test_middle_json_block_models.py+++ b/tests/unittest/test_middle_json_block_models.py@@ -1,6 +1,7 @@from __future__ import annotationsfrom copy import deepcopy+from typing import get_argsimport pytestfrom pydantic import ValidationError@@ -10,6 +11,8 @@ from mineru.backend.utils.raw_block_types import RAW_ONLY_BLOCK_TYPESfrom mineru.types import (BLOCK_ADAPTER,BLOCK_TYPES,+ BlockType,+ BlockTypes,CodeBlock,EquationBlock,ListBlock,@@ -77,7 +80,19 @@ def test_all_29_public_discriminators_parse_to_concrete_models() -> None:assert isinstance(parse_block(payloads["equation"]), EquationBlock)[email protected]("raw_type", ["algorithm", "caption", "footnote", "title", "phonetic"])+def test_public_block_type_declarations_match_block_union() -> None:+ """验证 BlockType、BlockTypes 和 BLOCK_TYPES 只公开 Block 联合的 discriminator。"""+ class_values = {+ value+ for name, value in vars(BlockType).items()+ if name.isupper()+ }++ assert class_values == BLOCK_TYPES+ assert set(get_args(BlockTypes)) == BLOCK_TYPES++[email protected]("raw_type", sorted(RAW_ONLY_BLOCK_TYPES))def test_raw_only_types_are_rejected(raw_type: str) -> None:"""验证 Analyze 私有 raw type 不能越过公开对象边界。"""assert raw_type in RAW_ONLY_BLOCK_TYPESdiff --git a/tests/unittest/test_middle_json_validator.py b/tests/unittest/test_middle_json_validator.pyindex 6d345acc..5ac9d850 100644--- a/tests/unittest/test_middle_json_validator.py+++ b/tests/unittest/test_middle_json_validator.py@@ -137,7 +137,7 @@ def _validate_block(block: Block, path: str, issues: list[ValidationIssue], pagemessage=f"unknown block type: {block.type}",))- elif _has_field(block, "type") and block.type == BlockType.TITLE:+ elif _has_field(block, "type") and block.type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:_validate_title_level(block, f"{path}.level", issues)if _has_field(block, "bbox"):@@ -461,7 +461,7 @@ def test_validate_pages_reports_unknown_block_type_and_bad_title_level() -> Nonepage.para_blocks.append(Block(index=1,- type=BlockType.TITLE,+ type=BlockType.PARAGRAPH_TITLE,bbox=(2.0, 2.0, 20.0, 20.0),lines=[Line(bbox=(2.0, 2.0, 20.0, 20.0), spans=[])],level=0,diff --git a/tests/unittest/test_para_block_utils.py b/tests/unittest/test_para_block_utils.pyindex b4148808..be1f851c 100644--- a/tests/unittest/test_para_block_utils.py+++ b/tests/unittest/test_para_block_utils.py@@ -112,7 +112,7 @@ def test_merge_para_text_blocks_requires_consecutive_cross_page_indices([(BlockType.IMAGE, True),(BlockType.CODE, True),- (BlockType.TITLE, False),+ (BlockType.DOC_TITLE, False),(BlockType.LIST, False),(BlockType.REF_TEXT, False),],diff --git a/tests/unittest/test_pdf_analyze_block_content.py b/tests/unittest/test_pdf_analyze_block_content.pyindex bafafce4..4d80ef01 100644--- a/tests/unittest/test_pdf_analyze_block_content.py+++ b/tests/unittest/test_pdf_analyze_block_content.py@@ -11,6 +11,7 @@ from mineru_vl_utils.structs import ExtractResultfrom mineru.backend import analyzefrom mineru.backend.utils.analyze_draft import _AnalyzeLine, _AnalyzeSpan+from mineru.backend.utils.raw_block_types import RAW_ALGORITHM, RAW_CAPTION, RAW_FOOTNOTEfrom mineru.backend.utils.span_pre_proc import (POST_OCR_FALLBACK_CONTENT_KEY,POST_OCR_FALLBACK_SCORE_KEY,@@ -237,11 +238,11 @@ def test_xhigh_vlm_blocks_normalize_visual_annotation_types() -> None:analyze._normalize_xhigh_vlm_blocks([page_blocks])assert [block["type"] for block in page_blocks] == [- BlockType.CAPTION,- BlockType.CAPTION,- BlockType.CAPTION,- BlockType.FOOTNOTE,- BlockType.FOOTNOTE,+ RAW_CAPTION,+ RAW_CAPTION,+ RAW_CAPTION,+ RAW_FOOTNOTE,+ RAW_FOOTNOTE,BlockType.TEXT,]assert [block["content"] for block in page_blocks] == [@@ -260,8 +261,8 @@ def test_five_pdf_text_types_keep_normalized_line_metadata() -> None:BlockType.TEXT,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,- BlockType.CAPTION,- BlockType.FOOTNOTE,+ RAW_CAPTION,+ RAW_FOOTNOTE,}text_block = {"type": BlockType.TEXT, "content": "text"}doc_title_block = {"type": BlockType.DOC_TITLE, "content": "doc title"}@@ -269,11 +270,11 @@ def test_five_pdf_text_types_keep_normalized_line_metadata() -> None:"type": BlockType.PARAGRAPH_TITLE,"content": "paragraph title",}- caption_block = {"type": BlockType.CAPTION, "content": "caption"}- footnote_block = {"type": BlockType.FOOTNOTE, "content": "footnote"}+ caption_block = {"type": RAW_CAPTION, "content": "caption"}+ footnote_block = {"type": RAW_FOOTNOTE, "content": "footnote"}unrelated_block = {- "type": BlockType.TITLE,- "content": "title",+ "type": BlockType.EQUATION,+ "content": "x=1","lines": [{"bbox": [0, 0, 1, 1]}],}page_blocks = [@@ -293,7 +294,7 @@ def test_five_pdf_text_types_keep_normalized_line_metadata() -> None:2: _build_text_lines("paragraph title"),3: _build_text_lines("caption line 1", "caption line 2"),4: _build_text_lines("footnote"),- 5: _build_text_lines("title"),+ 5: _build_text_lines("x=1"),},(200.0, 100.0),)@@ -471,7 +472,7 @@ def test_text_content_keeps_natural_paragraph_joining() -> None:assert content == "第一行第二行"[email protected]("block_type", [BlockType.CODE, BlockType.ALGORITHM])[email protected]("block_type", [BlockType.CODE, RAW_ALGORITHM])def test_code_content_keeps_existing_line_breaks(block_type: str) -> None:"""验证 code/algorithm 原有的逐行拼接语义保持不变。"""content = analyze._lines_to_block_content(diff --git a/tests/unittest/test_pdf_analyze_visual_blocks.py b/tests/unittest/test_pdf_analyze_visual_blocks.pyindex 77471d83..42bb54cd 100644--- a/tests/unittest/test_pdf_analyze_visual_blocks.py+++ b/tests/unittest/test_pdf_analyze_visual_blocks.py@@ -10,6 +10,7 @@ import pytestfrom PIL import Image, ImageDrawfrom mineru.backend import analyze+from mineru.backend.utils.raw_block_types import RAW_CAPTION, RAW_FOOTNOTE, RAW_PHONETICfrom mineru.types import BlockType, MiddleJson@@ -448,9 +449,9 @@ def test_xhigh_layout_image_fallback_uses_whitelist_for_area_but_absorbs_all_typBlockType.IMAGE,BlockType.CHART,BlockType.IMAGE_CAPTION,- BlockType.CAPTION,+ RAW_CAPTION,BlockType.IMAGE_FOOTNOTE,- BlockType.FOOTNOTE,+ RAW_FOOTNOTE,}layout_blocks_list = [[{"type": BlockType.IMAGE, "bbox": [0.0, 0.0, 1.0, 1.0], "angle": 0}]]insufficient_page = [@@ -471,7 +472,7 @@ def test_xhigh_layout_image_fallback_uses_whitelist_for_area_but_absorbs_all_typqualifying_page = [{"type": BlockType.IMAGE, "bbox": [0.0, 0.0, 0.4, 1.0]},{"type": BlockType.CHART, "bbox": [0.4, 0.0, 0.8, 1.0]},- {"type": BlockType.CAPTION, "bbox": [0.8, 0.0, 0.9, 1.0]},+ {"type": RAW_CAPTION, "bbox": [0.8, 0.0, 0.9, 1.0]},{"type": BlockType.TEXT, "bbox": [0.1, 0.1, 0.2, 0.2]},{"type": BlockType.TABLE, "bbox": [0.2, 0.2, 0.3, 0.3]},{"type": BlockType.EQUATION, "bbox": [0.3, 0.3, 0.4, 0.4]},@@ -600,7 +601,7 @@ def test_normalize_pdf_model_list_converts_phonetic_and_cleans_equation() -> Non"""验证 phonetic 转公开类型,同时 equation 保持类型并清理展示分隔符。"""model_list = [[{- "type": BlockType.PHONETIC,+ "type": RAW_PHONETIC,"bbox": [0.1, 0.1, 0.9, 0.2],"content": "phonetic","lines": [{"bbox": [0.1, 0.1, 0.9, 0.2]}],@@ -657,11 +658,11 @@ def test_formula_number_optimizer_does_not_accept_legacy_interline_equation() ->]-def test_normalize_pdf_model_list_rejects_unclassified_raw_title() -> None:- """验证未被 layout 结果分类的 raw title 以页块位置明确报错。"""+def test_normalize_pdf_model_list_rejects_unclassified_vlm_title() -> None:+ """验证未被 layout 结果分类的 VLM title 以页块位置明确报错。"""with pytest.raises(ValueError, match="page_idx=0, block_idx=0"):analyze._normalize_pdf_model_list(- [[{"type": BlockType.TITLE, "bbox": [0.1, 0.1, 0.9, 0.2], "content": "title"}]]+ [[{"type": analyze._VLM_UNCLASSIFIED_TITLE_TYPE, "bbox": [0.1, 0.1, 0.9, 0.2], "content": "title"}]])@@ -671,8 +672,8 @@ def test_normalize_pdf_model_list_rejects_unclassified_raw_title() -> None:BlockType.TEXT,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,- BlockType.CAPTION,- BlockType.FOOTNOTE,+ RAW_CAPTION,+ RAW_FOOTNOTE,],)@pytest.mark.parametrize(@@ -712,8 +713,8 @@ def test_normalize_pdf_model_list_removes_five_text_types_with_invalid_lines(BlockType.TEXT,BlockType.DOC_TITLE,BlockType.PARAGRAPH_TITLE,- BlockType.CAPTION,- BlockType.FOOTNOTE,+ RAW_CAPTION,+ RAW_FOOTNOTE,],)@pytest.mark.parametrize("invalid_content", [None, "", " ", ["not a string"]])@@ -749,12 +750,12 @@ def test_normalize_pdf_model_list_keeps_other_types_and_valid_text_order() -> No"lines": [{"bbox": [0.1, 0.1, 0.9, 0.2]}],}invalid_text = {- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"content": "caption","lines": [],}second_text = {- "type": BlockType.FOOTNOTE,+ "type": RAW_FOOTNOTE,"content": "second","lines": [{"bbox": [0.1, 0.8, 0.9, 0.9]}],}diff --git a/tests/unittest/test_table_merge.py b/tests/unittest/test_table_merge.pyindex 488b542c..3e87d75a 100644--- a/tests/unittest/test_table_merge.py+++ b/tests/unittest/test_table_merge.py@@ -152,9 +152,6 @@ def test_merge_table_requires_consecutive_increasing_page_indices(BlockType.PAGE_NUMBER,BlockType.PAGE_FOOTNOTE,BlockType.ASIDE_TEXT,- BlockType.HEADER_IMAGE,- BlockType.FOOTER_IMAGE,- BlockType.DISCARDED,],)def test_merge_table_skips_boundary_noise(block_type: str) -> None:diff --git a/tests/unittest/test_visual_magic_model_utils.py b/tests/unittest/test_visual_magic_model_utils.pyindex 7edc2ca3..5d945394 100644--- a/tests/unittest/test_visual_magic_model_utils.py+++ b/tests/unittest/test_visual_magic_model_utils.py@@ -10,6 +10,7 @@ from mineru.backend.utils.visual_magic_model_utils import (is_block_outside_visual_gap,regroup_visual_blocks,)+from mineru.backend.utils.raw_block_types import RAW_CAPTION, RAW_FOOTNOTEfrom mineru.types import BlockType@@ -41,7 +42,7 @@ def test_normalized_dict_bbox_matches_scaled_caption_geometry_without_rewrite()normalized_blocks = [{"index": 0,- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"bbox": [0.7, 0.1, 0.95, 0.12],"content": "Table 1","lines": _line_metadata(1),@@ -74,7 +75,7 @@ def test_normalized_dict_bbox_matches_scaled_caption_geometry_without_rewrite()def test_normalized_dict_bbox_matches_scaled_visual_parent_without_rewrite() -> None:"""验证 raw dict 归一化框与千倍坐标选择同一视觉父块且保留原框。"""previous_table = {"index": 0, "type": BlockType.TABLE_BODY, "bbox": [0.1, 0.1, 0.4, 0.4]}- caption = {"index": 1, "type": BlockType.CAPTION, "bbox": [0.1, 0.42, 0.4, 0.44]}+ caption = {"index": 1, "type": RAW_CAPTION, "bbox": [0.1, 0.42, 0.4, 0.44]}following_table = {"index": 2, "type": BlockType.TABLE_BODY, "bbox": [0.1, 0.8, 0.4, 0.95]}normalized_blocks = [previous_table, caption, following_table]original_bboxes = [list(block["bbox"]) for block in normalized_blocks]@@ -103,7 +104,7 @@ def test_normalized_dict_bbox_matches_scaled_visual_parent_without_rewrite() ->def test_normalized_dict_bbox_matches_scaled_visual_gap_geometry() -> None:"""验证归一化框在视觉间隔、相交和重叠判断中与千倍坐标一致。"""- child = {"index": 0, "type": BlockType.CAPTION, "bbox": [0.1, 0.1, 0.4, 0.2]}+ child = {"index": 0, "type": RAW_CAPTION, "bbox": [0.1, 0.1, 0.4, 0.2]}inside_gap = {"index": 1, "type": BlockType.TEXT, "bbox": [0.8, 0.3, 0.9, 0.4]}outside_gap = {"index": 2, "type": BlockType.TEXT, "bbox": [0.8, 0.8, 0.9, 0.9]}main = {"index": 3, "type": BlockType.TABLE_BODY, "bbox": [0.1, 0.6, 0.4, 0.7]}@@ -131,7 +132,7 @@ def test_dict_inline_caption_fragment_uses_common_fields() -> None:blocks = [{"index": 0,- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"bbox": [0.0, 0.0, 40.0, 10.0],"content": "Table 1","lines": _line_metadata(1),@@ -147,7 +148,7 @@ def test_dict_inline_caption_fragment_uses_common_fields() -> None:fallback_inline_caption_fragments(blocks, VISUAL_MAIN_TYPES)- assert companion["type"] == BlockType.CAPTION+ assert companion["type"] == RAW_CAPTIONdef test_dict_stacked_caption_fragment_uses_line_metadata() -> None:@@ -162,7 +163,7 @@ def test_dict_stacked_caption_fragment_uses_line_metadata() -> None:blocks = [{"index": 0,- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"bbox": [0.0, 0.0, 80.0, 10.0],"content": "Table 1","lines": _line_metadata(1),@@ -178,7 +179,7 @@ def test_dict_stacked_caption_fragment_uses_line_metadata() -> None:fallback_inline_caption_fragments(blocks, VISUAL_MAIN_TYPES)- assert single_line["type"] == BlockType.CAPTION+ assert single_line["type"] == RAW_CAPTIONsingle_line["type"] = BlockType.TEXTsingle_line["lines"] = _line_metadata(2)@@ -208,14 +209,14 @@ def test_dict_leading_table_continuation_reads_top_level_content() -> None:fallback_leading_table_continuation_captions(blocks, VISUAL_MAIN_TYPES)- assert continuation["type"] == BlockType.CAPTION+ assert continuation["type"] == RAW_CAPTIONdef test_regroup_visual_blocks_supports_bbox_dicts() -> None:"""验证带 bbox 的 dict 可沿用现有视觉关系规则生成 dict 两层块。"""caption = {"index": 0,- "type": BlockType.CAPTION,+ "type": RAW_CAPTION,"bbox": [0.0, 0.0, 80.0, 10.0],"content": "Figure 1","lines": [{"bbox": [0.0, 0.0, 80.0, 10.0]}],@@ -228,7 +229,7 @@ def test_regroup_visual_blocks_supports_bbox_dicts() -> None:}footnote = {"index": 2,- "type": BlockType.FOOTNOTE,+ "type": RAW_FOOTNOTE,"bbox": [0.0, 65.0, 80.0, 75.0],"content": "source","lines": [{"bbox": [0.0, 65.0, 80.0, 75.0]}],@@ -254,8 +255,8 @@ def test_regroup_visual_blocks_supports_bbox_dicts() -> None:assert "lines" not in image_footnoteassert "lines" in captionassert "lines" in footnote- assert caption["type"] == BlockType.CAPTION- assert footnote["type"] == BlockType.FOOTNOTE+ assert caption["type"] == RAW_CAPTION+ assert footnote["type"] == RAW_FOOTNOTEdef test_regroup_visual_blocks_preserves_dict_visual_metadata() -> None:@@ -322,7 +323,7 @@ def test_regroup_visual_blocks_keeps_cell_merge_on_dict_body() -> None:def test_regroup_visual_blocks_without_bbox_prefers_previous_parent() -> None:"""验证无 bbox 等距匹配优先选择 caption 前方的视觉主体。"""image_body = {"index": 0, "type": BlockType.IMAGE_BODY, "content": ""}- caption = {"index": 1, "type": BlockType.CAPTION, "content": "Figure 1"}+ caption = {"index": 1, "type": RAW_CAPTION, "content": "Figure 1"}table_body = {"index": 2, "type": BlockType.TABLE_BODY, "content": ""}grouped_blocks, unmatched_blocks = regroup_visual_blocks(@@ -370,7 +371,7 @@ def test_regroup_visual_blocks_supports_code_footnote() -> None:def test_regroup_visual_blocks_without_bbox_keeps_text_as_barrier() -> None:"""验证无 bbox 模式不会跨过普通文本关联 caption。"""- caption = {"index": 0, "type": BlockType.CAPTION, "content": "Table 1"}+ caption = {"index": 0, "type": RAW_CAPTION, "content": "Table 1"}text = {"index": 1, "type": BlockType.TEXT, "content": "paragraph"}table_body = {"index": 2, "type": BlockType.TABLE_BODY, "content": ""}@@ -389,9 +390,9 @@ def test_regroup_visual_blocks_without_bbox_keeps_text_as_barrier() -> None:def test_no_bbox_caption_fallback_uses_office_prefixes() -> None:"""验证无 bbox 的 table/image/chart 后置文本按 Office 前缀提升。"""cases = [- (BlockType.TABLE_BODY, "Table 1", BlockType.CAPTION),- (BlockType.IMAGE_BODY, "图 1", BlockType.CAPTION),- (BlockType.CHART_BODY, "Chart 1", BlockType.CAPTION),+ (BlockType.TABLE_BODY, "Table 1", RAW_CAPTION),+ (BlockType.IMAGE_BODY, "图 1", RAW_CAPTION),+ (BlockType.CHART_BODY, "Chart 1", RAW_CAPTION),(BlockType.IMAGE_BODY, "ordinary text", BlockType.TEXT),]