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: adjust title levels to enforce global hierarchy and ensure cell_merge is correctly associated with table root
myhloli2aa492e822c1
diff --git a/docs/next/middle-json/current-medium.md b/docs/next/middle-json/current-medium.mdindex bd403ecf..f929da58 100644--- a/docs/next/middle-json/current-medium.md+++ b/docs/next/middle-json/current-medium.md@@ -40,11 +40,16 @@| 字段 | 类型 | 要求 ||------|------|------|| `page_idx` | 非负整数 | 必填,使用实际页号映射 |-| `blocks` | `list[Block]` | 必填,默认为空列表 |+| `blocks` | `list[PageBlock]` | 必填,默认为空列表 |顶层 block 必须具有非负 `index`。同一页内的 index 必须唯一、严格递增,但允许缺号或从非零值开始。数组位置不能替代 index。+`PageBlock` 只允许 16 种页面根类型:`text/ref_text/doc_title/paragraph_title`、+`header/footer/page_number/page_footnote/aside_text`、`equation/list/index` 和+`image/table/chart/code`。视觉 `body/caption/footnote` 只能出现在对应父块内部;+通用 `Block` 联合仍可用于解析全部公开 discriminator。+## Block 公共字段所有具体 block 只共享以下定位字段:@@ -58,14 +63,14 @@bbox 必须是有限的 `[0, 1]` 归一化坐标,并满足 `x1 > x0`、`y1 > y0`。每个具体 block 都显式声明必填 `content`,公共基类不再杂糅类型专属字段。-公开 discriminator 共 29 个:+公开 discriminator 共 28 个:```textaside_textchart, chart_body, chart_caption, chart_footnotecode, code_body, code_caption, code_footnotedoc_title, paragraph_title-footer, formula_number, header+footer, headerimage, image_body, image_caption, image_footnoteequation, index, listpage_footnote, page_number, ref_text@@ -73,7 +78,7 @@ table, table_body, table_caption, table_footnotetext```-仅 raw 阶段允许的 `algorithm/caption/footnote/title/phonetic` 不属于+仅 raw 阶段允许的 `algorithm/caption/footnote/formula_number/phonetic` 不属于公开 union。其它旧 `BlockType` 常量也不会被严格反序列化接受。块级行间公式唯一使用 `equation`。Legacy Span 链中的@@ -85,13 +90,15 @@ text|------|-----------|----------|| `TextBlock` | `str` | `continues_prev`;不允许 `anchor` || `RefTextBlock` | `str` | 不允许 `continues_prev` |-| `DocTitleBlock` | `str` | `anchor` |-| `ParagraphTitleBlock` | `str` | `anchor`、正整数 `level` |-| `TableBlock` | 有序视觉子块列表 | `continues_prev` |-| `TableBodyBlock` | `str` | `cell_merge`、图片字段 |+| `DocTitleBlock` | `str` | `anchor`、必填 `level=1` |+| `ParagraphTitleBlock` | `str` | `anchor`、必填 `level>=2` |+| `PageAuxTextBlock` | `str` | 共享页眉、页脚、页码、边栏和页脚注释结构 |+| `TableBlock` | 有序视觉子块列表 | `continues_prev`、`cell_merge` |+| `TableBodyBlock` | `str` | 图片字段 || `CodeBlock` | 有序视觉子块列表 | `sub_type`、`guess_lang` || `ImageBlock/ChartBlock` | 有序视觉子块列表 | 开放字符串 `sub_type` |-| `ImageBodyBlock/ChartBodyBlock` | `str` 或 null | 图片字段 |+| `EquationBlock/ImageBodyBlock/TableBodyBlock/ChartBodyBlock` | `str` | 共享图片载荷内容结构 |+| `*AnnotationBlock` | `str` | 每个视觉家族共享 caption/footnote 结构 || 其它叶子 block | `str` | 仅各自声明的字段 |`CodeBlock(sub_type="code")` 必须有非空 `guess_lang`;@@ -99,7 +106,9 @@ text顶层 `text/list/table`,任何嵌套项即使显式写成 null 也会被拒绝。`merge_prev`、`is_numbered_style` 和 `section_number` 均不属于公开模型。-Office 自动标题编号已在对象化前写入 `ParagraphTitleBlock.content`。+标题使用全局文档层级:文档标题固定为一级,所有段落标题从二级开始。+Office 自动标题编号按 `level - 1` 的段落深度计算,并在对象化前写入+`ParagraphTitleBlock.content`。## 递归容器@@ -133,6 +142,8 @@ Office 目录规范化会递归移除普通 TextBlock 的 `anchor`。递归结每个父块必须且只能有一个对应 body;caption 和 footnote 可以有多个。父块有index 时 body 必须使用相同 index;父子同时有 bbox 时必须相等。+`cell_merge` 属于后一个 `table` 根块,描述其与前一个 table 的跨页视觉列续接;+`table_body` 只保存 HTML/文本和图片载荷。## 图片载荷与导出@@ -143,6 +154,10 @@ index 时 body 必须使用相同 index;父子同时有 bbox 时必须相等- `chart_body`- `equation`+这四类图片载荷 block 的 `content` 都必须是字符串。Analyze 会将 image/chart+缺失的文本表示或 raw `null` 规范化为空字符串;严格 Middle JSON 不接受+`content: null`。+普通 `to_dict()` / `to_json()` 不执行文件 I/O;可通过`exclude_block_fields={"image_base64"}` 递归排除图片字段。完整序列化保留base64 并支持严格 round-trip。@@ -157,6 +172,9 @@ images/page_{page_idx}_{type}_{index}_{ordinal}.{ext}第二种名称用于同一 HTML block 中的多张内嵌图片,ordinal 从 1 开始。导出JSON 不包含 `image_base64` 或 `data:image/...`,原始 MiddleJson 对象保持不变。+当前 schema 采用直接切换策略:缺失标题 `level`、`paragraph_title.level=1`、+`table_body.cell_merge` 和视觉载荷 `content: null` 均不会在严格反序列化时兼容。+## Analyze 私有对象公开 Block/PageInfo 不引用 `Line` 或 `Span`。Analyze 的文字回填与组行使用diff --git a/mineru/backend/analysis/pdf/normalization.py b/mineru/backend/analysis/pdf/normalization.pyindex d42a799d..542cfb05 100644--- a/mineru/backend/analysis/pdf/normalization.py+++ b/mineru/backend/analysis/pdf/normalization.py@@ -57,8 +57,10 @@ def _apply_layout_title_split(continueif _has_doc_title_overlap(title_bbox, doc_title_bboxes, overlap_threshold):block["type"] = BlockType.DOC_TITLE+ block["level"] = 1else:block["type"] = BlockType.PARAGRAPH_TITLE+ block["level"] = 2def _is_valid_pdf_text_block(block: dict[str, Any]) -> bool:diff --git a/mineru/backend/postprocess/lists.py b/mineru/backend/postprocess/lists.pyindex 36e49d36..9f424006 100644--- a/mineru/backend/postprocess/lists.py+++ b/mineru/backend/postprocess/lists.py@@ -20,32 +20,34 @@ def fix_office_paragraph_titles(model_list: list[list[dict[str, Any]]]) -> None:if block.get("type") != BlockType.PARAGRAPH_TITLE:continueraw_level = block.get("level")- level_is_valid = isinstance(raw_level, int) and not isinstance(raw_level, bool) and raw_level >= 1- level = raw_level if level_is_valid else 1- if not level_is_valid:- block.pop("level", None)+ level_is_valid = isinstance(raw_level, int) and not isinstance(raw_level, bool) and raw_level >= 2+ level = raw_level if level_is_valid else 2+ block["level"] = level+ numbering_depth = level - 1is_numbered_style = block.pop("is_numbered_style", None)block.pop("section_number", None)content = block.get("content")if not isinstance(content, str):continueif is_numbered_style is True:- for ancestor_level in range(1, level):+ for ancestor_level in range(1, numbering_depth):counters.setdefault(ancestor_level, 1)- counters[level] = counters.get(level, 0) + 1- _clear_deeper_title_counters(counters, level)- section_number = ".".join(str(counters[ancestor_level]) for ancestor_level in range(1, level + 1))+ counters[numbering_depth] = counters.get(numbering_depth, 0) + 1+ _clear_deeper_title_counters(counters, numbering_depth)+ section_number = ".".join(+ str(counters[ancestor_level]) for ancestor_level in range(1, numbering_depth + 1)+ )block["content"] = f"{section_number} {content}"continue- if is_numbered_style is False and level_is_valid:+ if is_numbered_style is False:number_match = re.match(r"^\s*(\d+(?:\.\d+)*)\b", _visible_text(content))if number_match is None:continuenumber_parts = [int(part) for part in number_match.group(1).split(".")]- if len(number_parts) != level:+ if len(number_parts) != numbering_depth:continuecounters.update((part_level, number) for part_level, number in enumerate(number_parts, start=1))- _clear_deeper_title_counters(counters, level)+ _clear_deeper_title_counters(counters, numbering_depth)def fix_pdf_list_blocks(diff --git a/mineru/backend/postprocess/page_blocks.py b/mineru/backend/postprocess/page_blocks.pyindex ffb3bf10..ba808da0 100644--- a/mineru/backend/postprocess/page_blocks.py+++ b/mineru/backend/postprocess/page_blocks.py@@ -80,6 +80,14 @@ def _normalize_raw_blocks(page_model_list: list[BlockDict]) -> list[BlockDict]:elif block_type == BlockType.EQUATION:block_content = clean_isolated_formula(block_content)+ if block_type in [BlockType.IMAGE_BODY, BlockType.CHART_BODY] and block_content is None:+ block_content = ""+ if block_type == BlockType.DOC_TITLE:+ block["level"] = 1+ elif block_type == BlockType.PARAGRAPH_TITLE:+ raw_level = block.get("level")+ block["level"] = raw_level if type(raw_level) is int and raw_level >= 2 else 2+if block_type not in [BlockType.IMAGE_BODY, BlockType.TABLE_BODY, BlockType.CHART_BODY]:if block_content:block_content = clean_content(block_content) or ""diff --git a/mineru/backend/postprocess/table_merge/content.py b/mineru/backend/postprocess/table_merge/content.pyindex 90bb7f75..f4079ced 100644--- a/mineru/backend/postprocess/table_merge/content.py+++ b/mineru/backend/postprocess/table_merge/content.py@@ -209,13 +209,13 @@ def _apply_cell_merge(cell_merge 按视觉列索引对齐,通过构建视觉列映射来正确匹配两个表格中可能因 rowspan 而具有不同 <td> 元素数量的行。- 元数据仅从当前页 table body 读取,不依赖外层 table block。+ 元数据从当前页 table 根块读取,HTML 与列结构仍由唯一 table body 提供。"""- current_body_block = current_state.body_block- if not isinstance(current_body_block, dict):+ current_table_block = current_state.owner_block+ if not isinstance(current_table_block, dict):return False- cell_merge = current_body_block.get("cell_merge")+ cell_merge = current_table_block.get("cell_merge")if not isinstance(cell_merge, list) or not cell_merge:return Falsediff --git a/mineru/backend/postprocess/visual.py b/mineru/backend/postprocess/visual.pyindex 968ba078..4c04d3a5 100644--- a/mineru/backend/postprocess/visual.py+++ b/mineru/backend/postprocess/visual.py@@ -432,6 +432,8 @@ def regroup_visual_blocks(body_block = deepcopy(main_block)_set_block_field(body_block, "type", mapping["body"])body_block.pop("sub_type", None)+ table_cell_merge_is_set = visual_type == BlockType.TABLE and "cell_merge" in body_block+ table_cell_merge = body_block.pop("cell_merge", None) if table_cell_merge_is_set else Nonecaptions: list[BlockDict] = []for caption in sorted(@@ -464,6 +466,8 @@ def regroup_visual_blocks(}if main_sub_type:two_layer_block["sub_type"] = main_sub_type+ if table_cell_merge_is_set:+ two_layer_block["cell_merge"] = table_cell_mergeif "bbox" in main_block:two_layer_block["bbox"] = deepcopy(main_block["bbox"])diff --git a/mineru/model/flash/docx/docx_converter.py b/mineru/model/flash/docx/docx_converter.pyindex 543de25a..1f04eef7 100644--- a/mineru/model/flash/docx/docx_converter.py+++ b/mineru/model/flash/docx/docx_converter.py@@ -1400,7 +1400,7 @@ class DocxConverter:if content_text:title_block = {"type": BlockType.PARAGRAPH_TITLE,- "level": ilevel + 1,+ "level": ilevel + 2,"is_numbered_style": is_numbered,"content": content_text,}@@ -1430,6 +1430,7 @@ class DocxConverter:if content_text != "":title_block = {"type": BlockType.DOC_TITLE,+ "level": 1,"content": content_text,}if paragraph_anchor:@@ -1443,7 +1444,7 @@ class DocxConverter:if content_text != "":h_block = {"type": BlockType.PARAGRAPH_TITLE,- "level": p_level if p_level is not None else 2,+ "level": max(p_level + 1, 2) if p_level is not None else 2,"is_numbered_style": is_numbered_style,"content": content_text,}diff --git a/mineru/model/flash/pptx/pptx_converter.py b/mineru/model/flash/pptx/pptx_converter.pyindex f4061cd6..050ed47e 100644--- a/mineru/model/flash/pptx/pptx_converter.py+++ b/mineru/model/flash/pptx/pptx_converter.py@@ -1800,7 +1800,7 @@ class PptxConverter:if title_role == _PPTX_TITLE_ROLE_CENTER and is_first_visible_slide:block["type"] = BlockType.DOC_TITLE- block.pop("level", None)+ block["level"] = 1block.pop("is_numbered_style", None)else:block["type"] = BlockType.PARAGRAPH_TITLEdiff --git a/mineru/model/flash/xlsx/xlsx_converter.py b/mineru/model/flash/xlsx/xlsx_converter.pyindex 13b88091..5640ac25 100644--- a/mineru/model/flash/xlsx/xlsx_converter.py+++ b/mineru/model/flash/xlsx/xlsx_converter.py@@ -267,6 +267,7 @@ class XlsxConverter:"""构造工作表标题块,复用 Office 标题渲染链路输出 Markdown 标题。"""return {"type": BlockType.PARAGRAPH_TITLE,+ "level": 2,"content": sheet_title,}diff --git a/mineru/types.py b/mineru/types.pyindex 5e795ac4..8fe3f531 100644--- a/mineru/types.py+++ b/mineru/types.py@@ -176,6 +176,25 @@ BlockTypes = Literal[BlockType.PARAGRAPH_TITLE,]+PageBlockTypes = Literal[+ BlockType.IMAGE,+ BlockType.TABLE,+ BlockType.CHART,+ BlockType.TEXT,+ BlockType.EQUATION,+ BlockType.LIST,+ BlockType.INDEX,+ BlockType.CODE,+ BlockType.REF_TEXT,+ BlockType.HEADER,+ BlockType.FOOTER,+ BlockType.PAGE_NUMBER,+ BlockType.ASIDE_TEXT,+ BlockType.PAGE_FOOTNOTE,+ BlockType.DOC_TITLE,+ BlockType.PARAGRAPH_TITLE,+]+BLOCK_TYPES = {BlockType.IMAGE,BlockType.TABLE,@@ -207,6 +226,25 @@ BLOCK_TYPES = {BlockType.PARAGRAPH_TITLE,}+PAGE_BLOCK_TYPES = {+ BlockType.IMAGE,+ BlockType.TABLE,+ BlockType.CHART,+ BlockType.TEXT,+ BlockType.EQUATION,+ BlockType.LIST,+ BlockType.INDEX,+ BlockType.CODE,+ BlockType.REF_TEXT,+ BlockType.HEADER,+ BlockType.FOOTER,+ BlockType.PAGE_NUMBER,+ BlockType.ASIDE_TEXT,+ BlockType.PAGE_FOOTNOTE,+ BlockType.DOC_TITLE,+ BlockType.PARAGRAPH_TITLE,+}+VISUAL_RELATION_IGNORED_TYPES = {BlockType.HEADER,BlockType.FOOTER,@@ -330,53 +368,48 @@ class BlockBase(_StrictMiddleModel):return bbox # type: ignore[return-value]-class TextBlock(BlockBase):- type: Literal[BlockType.TEXT]- content: str- continues_prev: bool | None = None+class StringContentBlock(BlockBase):+ """所有字符串内容 block 的共享结构。"""--class RefTextBlock(BlockBase):- type: Literal[BlockType.REF_TEXT]content: str-class DocTitleBlock(BlockBase):- type: Literal[BlockType.DOC_TITLE]- content: str- anchor: str | None = None+class TextBlock(StringContentBlock):+ type: Literal[BlockType.TEXT]+ continues_prev: bool | None = None-class ParagraphTitleBlock(BlockBase):- type: Literal[BlockType.PARAGRAPH_TITLE]- content: str- anchor: str | None = None- level: int | None = Field(default=None, ge=1)+class RefTextBlock(StringContentBlock):+ type: Literal[BlockType.REF_TEXT]-class AsideTextBlock(BlockBase):- type: Literal[BlockType.ASIDE_TEXT]- content: str+class TitleBlockBase(StringContentBlock):+ """文档标题与段落标题的全局层级公共结构。"""+ anchor: str | None = None+ level: int-class HeaderBlock(BlockBase):- type: Literal[BlockType.HEADER]- content: str+class DocTitleBlock(TitleBlockBase):+ type: Literal[BlockType.DOC_TITLE]+ level: Literal[1]-class FooterBlock(BlockBase):- type: Literal[BlockType.FOOTER]- content: str+class ParagraphTitleBlock(TitleBlockBase):+ type: Literal[BlockType.PARAGRAPH_TITLE]+ level: int = Field(ge=2)-class PageNumberBlock(BlockBase):- type: Literal[BlockType.PAGE_NUMBER]- content: str+class PageAuxTextBlock(StringContentBlock):+ """页眉、页脚、页码、边栏和页脚注释的共享文本结构。"""-class PageFootnoteBlock(BlockBase):- type: Literal[BlockType.PAGE_FOOTNOTE]- content: str+ type: Literal[+ BlockType.HEADER,+ BlockType.FOOTER,+ BlockType.PAGE_NUMBER,+ BlockType.ASIDE_TEXT,+ BlockType.PAGE_FOOTNOTE,+ ]class ImagePayloadBlock(BlockBase):@@ -396,70 +429,54 @@ class ImagePayloadBlock(BlockBase):return validate_image_sidecar_path(value)-class EquationBlock(ImagePayloadBlock):- type: Literal[BlockType.EQUATION]+class ImagePayloadContentBlock(ImagePayloadBlock):+ """统一携带字符串内容和图片载荷的 block 结构。"""+content: str-class ImageBodyBlock(ImagePayloadBlock):+class EquationBlock(ImagePayloadContentBlock):+ type: Literal[BlockType.EQUATION]+++class ImageBodyBlock(ImagePayloadContentBlock):type: Literal[BlockType.IMAGE_BODY]- content: str | None-class TableBodyBlock(ImagePayloadBlock):+class TableBodyBlock(ImagePayloadContentBlock):type: Literal[BlockType.TABLE_BODY]- content: str- cell_merge: list[Literal[0, 1]] | None = None-class ChartBodyBlock(ImagePayloadBlock):+class ChartBodyBlock(ImagePayloadContentBlock):type: Literal[BlockType.CHART_BODY]- content: str | None-class CodeBodyBlock(BlockBase):+class CodeBodyBlock(StringContentBlock):type: Literal[BlockType.CODE_BODY]- content: str---class ImageCaptionBlock(BlockBase):- type: Literal[BlockType.IMAGE_CAPTION]- content: str---class ImageFootnoteBlock(BlockBase):- type: Literal[BlockType.IMAGE_FOOTNOTE]- content: str-class TableCaptionBlock(BlockBase):- type: Literal[BlockType.TABLE_CAPTION]- content: str+class ImageAnnotationBlock(StringContentBlock):+ """图片标题与图片脚注的共享结构。"""+ type: Literal[BlockType.IMAGE_CAPTION, BlockType.IMAGE_FOOTNOTE]-class TableFootnoteBlock(BlockBase):- type: Literal[BlockType.TABLE_FOOTNOTE]- content: str+class TableAnnotationBlock(StringContentBlock):+ """表格标题与表格脚注的共享结构。"""-class ChartCaptionBlock(BlockBase):- type: Literal[BlockType.CHART_CAPTION]- content: str+ type: Literal[BlockType.TABLE_CAPTION, BlockType.TABLE_FOOTNOTE]-class ChartFootnoteBlock(BlockBase):- type: Literal[BlockType.CHART_FOOTNOTE]- content: str+class ChartAnnotationBlock(StringContentBlock):+ """图表标题与图表脚注的共享结构。"""+ type: Literal[BlockType.CHART_CAPTION, BlockType.CHART_FOOTNOTE]-class CodeCaptionBlock(BlockBase):- type: Literal[BlockType.CODE_CAPTION]- content: str+class CodeAnnotationBlock(StringContentBlock):+ """代码标题与代码脚注的共享结构。"""-class CodeFootnoteBlock(BlockBase):- type: Literal[BlockType.CODE_FOOTNOTE]- content: str+ type: Literal[BlockType.CODE_CAPTION, BlockType.CODE_FOOTNOTE]ListChildBlock: TypeAlias = Annotated[@@ -507,7 +524,7 @@ class _VisualBlockBase(BlockBase):ImageChildBlock: TypeAlias = Annotated[- Union[ImageBodyBlock, ImageCaptionBlock, ImageFootnoteBlock],+ Union[ImageBodyBlock, ImageAnnotationBlock],Field(discriminator="type"),]@@ -520,7 +537,7 @@ class ImageBlock(_VisualBlockBase):TableChildBlock: TypeAlias = Annotated[- Union[TableBodyBlock, TableCaptionBlock, TableFootnoteBlock],+ Union[TableBodyBlock, TableAnnotationBlock],Field(discriminator="type"),]@@ -529,11 +546,12 @@ class TableBlock(_VisualBlockBase):type: Literal[BlockType.TABLE]content: list[TableChildBlock]continues_prev: bool | None = None+ cell_merge: list[Literal[0, 1]] | None = None_body_type: ClassVar[str] = BlockType.TABLE_BODYChartChildBlock: TypeAlias = Annotated[- Union[ChartBodyBlock, ChartCaptionBlock, ChartFootnoteBlock],+ Union[ChartBodyBlock, ChartAnnotationBlock],Field(discriminator="type"),]@@ -546,7 +564,7 @@ class ChartBlock(_VisualBlockBase):CodeChildBlock: TypeAlias = Annotated[- Union[CodeBodyBlock, CodeCaptionBlock, CodeFootnoteBlock],+ Union[CodeBodyBlock, CodeAnnotationBlock],Field(discriminator="type"),]@@ -573,35 +591,46 @@ ListBlock.model_rebuild()IndexBlock.model_rebuild()+PageBlock: TypeAlias = Annotated[+ Union[+ TextBlock,+ RefTextBlock,+ DocTitleBlock,+ ParagraphTitleBlock,+ PageAuxTextBlock,+ EquationBlock,+ ListBlock,+ IndexBlock,+ ImageBlock,+ TableBlock,+ ChartBlock,+ CodeBlock,+ ],+ Field(discriminator="type"),+]++Block: TypeAlias = Annotated[Union[TextBlock,RefTextBlock,DocTitleBlock,ParagraphTitleBlock,- AsideTextBlock,- HeaderBlock,- FooterBlock,- PageNumberBlock,- PageFootnoteBlock,+ PageAuxTextBlock,EquationBlock,ListBlock,IndexBlock,ImageBodyBlock,- ImageCaptionBlock,- ImageFootnoteBlock,+ ImageAnnotationBlock,ImageBlock,TableBodyBlock,- TableCaptionBlock,- TableFootnoteBlock,+ TableAnnotationBlock,TableBlock,ChartBodyBlock,- ChartCaptionBlock,- ChartFootnoteBlock,+ ChartAnnotationBlock,ChartBlock,CodeBodyBlock,- CodeCaptionBlock,- CodeFootnoteBlock,+ CodeAnnotationBlock,CodeBlock,],Field(discriminator="type"),@@ -627,7 +656,7 @@ class PageInfo(_StrictMiddleModel):"""一页的严格 Middle JSON 内容。"""page_idx: int = Field(ge=0)- blocks: list[Block] = Field(default_factory=list)+ blocks: list[PageBlock] = Field(default_factory=list)@model_validator(mode="after")def _validate_page_tree(self) -> PageInfo:diff --git a/mineru/utils/llm_aided.py b/mineru/utils/llm_aided.pyindex 85b7973b..3b929b89 100644--- a/mineru/utils/llm_aided.py+++ b/mineru/utils/llm_aided.py@@ -225,7 +225,11 @@ def _apply_levels_to_blocks(title_block_refs: list[tuple[PageInfo, Block]], levereturnfor i, (_, block) in enumerate(title_block_refs):- block.level = int(levels_by_index[i])+ resolved_level = int(levels_by_index[i])+ if block.type == BlockType.DOC_TITLE:+ block.level = 1+ elif block.type == BlockType.PARAGRAPH_TITLE:+ block.level = max(resolved_level, 2)def _get_title_block_identity(block: Block) -> tuple[str, int] | tuple[str, BBox, str]:@@ -291,7 +295,7 @@ def _offset_paragraph_title_levels(levels_by_index: dict[int, int] | None) -> diif not levels_by_index:return levels_by_index- return {index: 2 if level == 1 else level for index, level in levels_by_index.items()}+ return {index: max(int(level), 2) for index, level in levels_by_index.items()}def _request_paragraph_group_levels(diff --git a/tests/unittest/test_flash_office_title_types.py b/tests/unittest/test_flash_office_title_types.pyindex defb8684..ce6e45a2 100644--- a/tests/unittest/test_flash_office_title_types.py+++ b/tests/unittest/test_flash_office_title_types.py@@ -4,6 +4,7 @@ from io import BytesIOfrom pathlib import Pathfrom typing import Any+from docx import Documentfrom pptx import Presentationfrom pptx.enum.shapes import PP_PLACEHOLDER@@ -106,21 +107,38 @@ def test_docx_model_splits_document_and_paragraph_titles() -> None:doc_title = _find_block_by_content(blocks, "MinerU supports DOCX document parsing now")assert doc_title["type"] == BlockType.DOC_TITLE- assert set(doc_title) <= {"type", "content", "anchor"}- assert "level" not in doc_title+ assert set(doc_title) <= {"type", "content", "anchor", "level"}+ assert doc_title["level"] == 1assert "is_numbered_style" not in doc_titleheading = _find_block_by_content(blocks, "后面是正常的章节标题")assert heading["type"] == BlockType.PARAGRAPH_TITLE- assert heading["level"] == 1+ assert heading["level"] == 2assert heading["is_numbered_style"] is Falsenumbered_heading = _find_block_containing(blocks, "有序列表构成的章节标题")assert numbered_heading["type"] == BlockType.PARAGRAPH_TITLE- assert numbered_heading["level"] == 1+ assert numbered_heading["level"] == 2assert numbered_heading["is_numbered_style"] is True+def test_docx_heading_levels_are_shifted_below_document_title() -> None:+ """验证 DOCX Title/Heading 1/Heading 2 输出全局一级、二级、三级层级。"""+ document = Document()+ document.add_paragraph("Document", style="Title")+ document.add_heading("Heading one", level=1)+ document.add_heading("Heading two", level=2)+ stream = BytesIO()+ document.save(stream)+ stream.seek(0)++ blocks = _flatten_pages(DocxModel().predict(stream))++ assert _find_block_by_content(blocks, "Document")["level"] == 1+ assert _find_block_containing(blocks, "Heading one")["level"] == 2+ assert _find_block_containing(blocks, "Heading two")["level"] == 3++def test_pptx_model_splits_title_placeholders_and_subtitle() -> None:"""验证 PPTX 真实样例的首页主标题、Subtitle 和普通页标题映射。"""pages = _predict_sample(PptxModel(), "pptx")@@ -135,8 +153,8 @@ def test_pptx_model_splits_title_placeholders_and_subtitle() -> None:doc_title = _find_block_by_content(pages[0], "Test Table Slide")assert doc_title["type"] == BlockType.DOC_TITLE- assert set(doc_title) <= {"type", "content", "anchor"}- assert "level" not in doc_title+ assert set(doc_title) <= {"type", "content", "anchor", "level"}+ assert doc_title["level"] == 1assert "is_numbered_style" not in doc_titlesubtitle = _find_block_by_content(pages[0], "With footnote")@@ -189,7 +207,7 @@ def test_pptx_title_candidates_are_finalized_without_losing_levels() -> None:BlockType.PARAGRAPH_TITLE,BlockType.PARAGRAPH_TITLE,]- assert "level" not in blocks[0]+ assert blocks[0]["level"] == 1assert "is_numbered_style" not in blocks[0]assert "level" not in blocks[1]assert blocks[2]["level"] == 2@@ -266,7 +284,9 @@ def test_pptx_notes_only_slide_does_not_consume_document_title() -> None:blocks = _flatten_pages(pages)assert _find_block_by_content(blocks, "Presenter note")["type"] == BlockType.PAGE_FOOTNOTE- assert _find_block_by_content(blocks, "Document title")["type"] == BlockType.DOC_TITLE+ document_title = _find_block_by_content(blocks, "Document title")+ assert document_title["type"] == BlockType.DOC_TITLE+ assert document_title["level"] == 1assert _find_block_by_content(blocks, "Document subtitle")["type"] == BlockType.TEXTlater_title = _find_block_by_content(blocks, "Section cover")assert later_title["type"] == BlockType.PARAGRAPH_TITLE@@ -274,13 +294,13 @@ def test_pptx_notes_only_slide_does_not_consume_document_title() -> None:assert all(_PPTX_TITLE_CANDIDATE_KEY not in block for block in blocks)-def test_xlsx_model_emits_sheet_names_as_paragraph_titles() -> None:- """验证 XLSX 多 Sheet 名称全部输出为无 level 的段落标题。"""+def test_xlsx_model_emits_sheet_names_as_level_two_paragraph_titles() -> None:+ """验证 XLSX 多 Sheet 名称全部输出为二级段落标题。"""pages = _predict_sample(XlsxModel(), "xlsx")blocks = _flatten_pages(pages)sheet_titles = [_find_block_by_content(blocks, sheet_name) for sheet_name in ("Sheet1", "Sheet2", "Sheet3")]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["level"] == 2 for block in sheet_titles)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 3a315ab9..730550c1 100644--- a/tests/unittest/test_middle_json_block_models.py+++ b/tests/unittest/test_middle_json_block_models.py@@ -8,17 +8,25 @@ from pydantic import ValidationErrorimport mineru.types as types_modulefrom mineru.backend.postprocess.pages import model_list_to_pages-from mineru.types import RAW_FORMULA_NUMBER, RAW_ONLY_BLOCK_TYPESfrom mineru.types import (BLOCK_ADAPTER,BLOCK_TYPES,+ PAGE_BLOCK_TYPES,+ RAW_FORMULA_NUMBER,+ RAW_ONLY_BLOCK_TYPES,BlockType,BlockTypes,+ ChartAnnotationBlock,+ CodeAnnotationBlock,CodeBlock,EquationBlock,+ ImageAnnotationBlock,ListBlock,MiddleJson,+ PageAuxTextBlock,+ PageBlockTypes,PageInfo,+ TableAnnotationBlock,TextBlock,parse_block,)@@ -29,7 +37,7 @@ def _public_block_payloads() -> dict[str, dict[str, object]]:text_leaf = {"type": "text", "content": "item"}payloads: dict[str, dict[str, object]] = {"aside_text": {"type": "aside_text", "content": "aside"},- "doc_title": {"type": "doc_title", "content": "title"},+ "doc_title": {"type": "doc_title", "content": "title", "level": 1},"footer": {"type": "footer", "content": "footer"},"header": {"type": "header", "content": "header"},"index": {"type": "index", "content": [text_leaf]},@@ -37,16 +45,16 @@ def _public_block_payloads() -> dict[str, dict[str, object]]:"list": {"type": "list", "content": [text_leaf]},"page_footnote": {"type": "page_footnote", "content": "note"},"page_number": {"type": "page_number", "content": "1"},- "paragraph_title": {"type": "paragraph_title", "content": "section"},+ "paragraph_title": {"type": "paragraph_title", "content": "section", "level": 2},"ref_text": {"type": "ref_text", "content": "reference"},"text": {"type": "text", "content": "text"},- "image_body": {"type": "image_body", "content": None},+ "image_body": {"type": "image_body", "content": ""},"image_caption": {"type": "image_caption", "content": "caption"},"image_footnote": {"type": "image_footnote", "content": "note"},"table_body": {"type": "table_body", "content": "<table></table>"},"table_caption": {"type": "table_caption", "content": "caption"},"table_footnote": {"type": "table_footnote", "content": "note"},- "chart_body": {"type": "chart_body", "content": None},+ "chart_body": {"type": "chart_body", "content": ""},"chart_caption": {"type": "chart_caption", "content": "caption"},"chart_footnote": {"type": "chart_footnote", "content": "note"},"code_body": {"type": "code_body", "content": "print(1)"},@@ -86,6 +94,52 @@ def test_public_block_type_declarations_match_block_union() -> None:assert class_values == BLOCK_TYPESassert set(get_args(BlockTypes)) == BLOCK_TYPES+ assert set(get_args(PageBlockTypes)) == PAGE_BLOCK_TYPES+++def test_shared_models_preserve_all_discriminator_values() -> None:+ """验证同结构 discriminator 共用模型,但仍保留原始 type 语义。"""+ assert isinstance(parse_block({"type": "header", "content": "h"}), PageAuxTextBlock)+ assert isinstance(parse_block({"type": "image_caption", "content": "c"}), ImageAnnotationBlock)+ assert isinstance(parse_block({"type": "table_footnote", "content": "f"}), TableAnnotationBlock)+ assert isinstance(parse_block({"type": "chart_caption", "content": "c"}), ChartAnnotationBlock)+ assert isinstance(parse_block({"type": "code_footnote", "content": "f"}), CodeAnnotationBlock)+++def test_title_levels_follow_global_hierarchy() -> None:+ """验证文档标题固定为一级,段落标题必须从二级开始。"""+ doc_title = parse_block({"type": "doc_title", "content": "doc", "level": 1})+ paragraph_title = parse_block({"type": "paragraph_title", "content": "section", "level": 2})++ assert doc_title.to_dict()["level"] == 1+ assert paragraph_title.to_dict()["level"] == 2+ for payload in (+ {"type": "doc_title", "content": "doc"},+ {"type": "doc_title", "content": "doc", "level": 2},+ {"type": "paragraph_title", "content": "section"},+ {"type": "paragraph_title", "content": "section", "level": 1},+ ):+ with pytest.raises(ValidationError):+ parse_block(payload)++[email protected]("block_type", ["equation", "image_body", "table_body", "chart_body"])+def test_image_payload_content_must_be_string(block_type: str) -> None:+ """验证所有图片载荷块在严格 Middle JSON 中都拒绝 null content。"""+ with pytest.raises(ValidationError):+ parse_block({"type": block_type, "content": None})+++def test_cell_merge_belongs_only_to_table_root() -> None:+ """验证 cell_merge 只允许位于 table 根块。"""+ table_payload = deepcopy(_public_block_payloads()["table"])+ table_payload["cell_merge"] = [1, 0]++ table = parse_block(table_payload)++ assert table.cell_merge == [1, 0]+ with pytest.raises(ValidationError):+ parse_block({"type": "table_body", "content": "<table></table>", "cell_merge": [1, 0]})@pytest.mark.parametrize("raw_type", sorted(RAW_ONLY_BLOCK_TYPES))@@ -154,6 +208,19 @@ def test_removed_block_classes_are_not_exposed() -> None:legacy_equation_model_name = "Interline" + "EquationBlock"removed_names = ("TitleBlock",+ "AsideTextBlock",+ "HeaderBlock",+ "FooterBlock",+ "PageNumberBlock",+ "PageFootnoteBlock",+ "ImageCaptionBlock",+ "ImageFootnoteBlock",+ "TableCaptionBlock",+ "TableFootnoteBlock",+ "ChartCaptionBlock",+ "ChartFootnoteBlock",+ "CodeCaptionBlock",+ "CodeFootnoteBlock","HeaderImageBlock","FooterImageBlock",legacy_equation_model_name,@@ -243,7 +310,7 @@ def test_visual_parent_body_location_contract() -> None:{"type": "image","index": 1,- "content": [{"type": "image_body", "index": 2, "content": None}],+ "content": [{"type": "image_body", "index": 2, "content": ""}],})with pytest.raises(ValidationError, match="bbox"):@@ -251,7 +318,21 @@ def test_visual_parent_body_location_contract() -> None:{"type": "image","bbox": [0.1, 0.1, 0.9, 0.9],- "content": [{"type": "image_body", "bbox": [0.2, 0.2, 0.8, 0.8], "content": None}],+ "content": [{"type": "image_body", "bbox": [0.2, 0.2, 0.8, 0.8], "content": ""}],+ }+ )+++def test_visual_parent_rejects_other_family_annotation() -> None:+ """验证合并 annotation 模型后仍禁止视觉父块接收其他家族子块。"""+ with pytest.raises(ValidationError):+ parse_block(+ {+ "type": "image",+ "content": [+ {"type": "image_body", "content": ""},+ {"type": "table_caption", "content": "wrong"},+ ],})@@ -294,6 +375,33 @@ def test_page_info_requires_unique_strictly_increasing_top_indices() -> None:)[email protected]("block_type", ["image_body", "table_caption", "code_footnote"])+def test_page_info_rejects_visual_child_as_top_level(block_type: str) -> None:+ """验证视觉 body/caption/footnote 只能出现在对应父块内部。"""+ with pytest.raises(ValidationError):+ PageInfo.model_validate(+ {+ "page_idx": 0,+ "blocks": [{"type": block_type, "index": 0, "content": ""}],+ }+ )+++def test_page_info_accepts_all_page_root_discriminators() -> None:+ """验证 PAGE_BLOCK_TYPES 中的全部页面根类型都能进入 PageInfo。"""+ payloads = _public_block_payloads()+ for block_type in PAGE_BLOCK_TYPES:+ payload = deepcopy(payloads[block_type])+ payload["index"] = 0+ content = payload.get("content")+ if isinstance(content, list):+ for child in content:+ if isinstance(child, dict) and str(child.get("type", "")).endswith("_body"):+ child["index"] = 0+ page = PageInfo.model_validate({"page_idx": 0, "blocks": [payload]})+ assert page.blocks[0].type == block_type++def test_nested_continues_prev_is_rejected_by_page_tree() -> None:"""验证 continues_prev 只能出现在页面顶层 text/list/table。"""with pytest.raises(ValidationError, match="nested"):diff --git a/tests/unittest/test_pdf_analyze_block_content.py b/tests/unittest/test_pdf_analyze_block_content.pyindex cdc60625..d0a3d935 100644--- a/tests/unittest/test_pdf_analyze_block_content.py+++ b/tests/unittest/test_pdf_analyze_block_content.py@@ -10,7 +10,7 @@ from mineru_vl_utils.structs import ContentBlock as VlmContentBlockfrom mineru_vl_utils.structs import ExtractResultfrom mineru.backend import analyze-from mineru.backend.analysis.pdf import constants, layout, ocr, pipeline, tables, window+from mineru.backend.analysis.pdf import constants, layout, normalization, ocr, pipeline, tables, windowfrom mineru.backend.analysis.pdf.text import content as text_contentfrom mineru.backend.analysis.pdf.text.models import _AnalyzeLine, _AnalyzeSpanfrom mineru.types import RAW_ALGORITHM, RAW_CAPTION, RAW_FOOTNOTE@@ -67,6 +67,24 @@ def _build_post_ocr_page_block_lines(return page_block_lines_list, spans+def test_layout_title_split_assigns_global_title_levels() -> None:+ """验证 PDF 标题拆分后文档标题为一级,段落标题从二级开始。"""+ model_list = [+ [+ {"type": constants._VLM_UNCLASSIFIED_TITLE_TYPE, "bbox": [0.1, 0.1, 0.9, 0.2], "content": "Doc"},+ {"type": constants._VLM_UNCLASSIFIED_TITLE_TYPE, "bbox": [0.1, 0.3, 0.9, 0.4], "content": "Section"},+ ]+ ]+ layout_res = [[{"label": BlockType.DOC_TITLE, "bbox": [0.1, 0.1, 0.9, 0.2]}]]++ normalization._apply_layout_title_split(model_list, layout_res, [(1000, 1000)])++ assert [(block["type"], block["level"]) for block in model_list[0]] == [+ (BlockType.DOC_TITLE, 1),+ (BlockType.PARAGRAPH_TITLE, 2),+ ]++def test_convert_vlm_results_to_model_list_uses_builtin_containers() -> None:"""验证 VLM 容器子类会转换为原生 list/dict,且不会修改源块。"""source_block = VlmContentBlock(diff --git a/tests/unittest/test_postprocess_pages.py b/tests/unittest/test_postprocess_pages.pyindex 25ca76d6..061d16cb 100644--- a/tests/unittest/test_postprocess_pages.py+++ b/tests/unittest/test_postprocess_pages.py@@ -4,6 +4,7 @@ import pytestfrom mineru.backend.postprocess.pages import model_list_to_pagesfrom mineru.types import (+ ChartBlock,EquationBlock,ImageBlock,ListBlock,@@ -120,11 +121,11 @@ def test_office_paragraph_numbering_is_document_wide_and_copy_only() -> None:model_list = [[{"type": "paragraph_title", "content": "<b>A</b>", "level": 1, "is_numbered_style": True},- {"type": "paragraph_title", "content": "B", "level": 2, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "B", "level": 3, "is_numbered_style": True},],[- {"type": "paragraph_title", "content": "1.4 Explicit", "level": 2, "is_numbered_style": False},- {"type": "paragraph_title", "content": "C", "level": 2, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "1.4 Explicit", "level": 3, "is_numbered_style": False},+ {"type": "paragraph_title", "content": "C", "level": 3, "is_numbered_style": True},{"type": "paragraph_title", "content": "No level", "is_numbered_style": True},],]@@ -141,7 +142,7 @@ def test_office_paragraph_numbering_is_document_wide_and_copy_only() -> None:"1.5 C","2 No level",]- assert titles[-1].level is None+ assert [title.level for title in titles] == [2, 3, 3, 3, 2]assert model_list == original@@ -149,13 +150,13 @@ def test_office_paragraph_numbering_clears_deeper_levels() -> None:"""验证标题返回浅层时会清理旧深层计数,后续重新从一开始编号。"""model_list = [[- {"type": "paragraph_title", "content": "A", "level": 1, "is_numbered_style": True},- {"type": "paragraph_title", "content": "B", "level": 2, "is_numbered_style": True},- {"type": "paragraph_title", "content": "C", "level": 3, "is_numbered_style": True},- {"type": "paragraph_title", "content": "D", "level": 2, "is_numbered_style": True},- {"type": "paragraph_title", "content": "E", "level": 3, "is_numbered_style": True},- {"type": "paragraph_title", "content": "F", "level": 1, "is_numbered_style": True},- {"type": "paragraph_title", "content": "G", "level": 2, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "A", "level": 2, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "B", "level": 3, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "C", "level": 4, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "D", "level": 3, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "E", "level": 4, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "F", "level": 2, "is_numbered_style": True},+ {"type": "paragraph_title", "content": "G", "level": 3, "is_numbered_style": True},]]@@ -179,6 +180,30 @@ def test_visual_body_drops_empty_parent_subtype() -> None:assert isinstance(page.blocks[0], ImageBlock)assert page.blocks[0].sub_type is Noneassert page.blocks[0].content[0].type == "image_body"+ assert page.blocks[0].content[0].content == ""+++def test_chart_none_content_is_normalized_to_empty_string() -> None:+ """验证 raw chart 的 null content 在严格对象化前规范为空字符串。"""+ page = model_list_to_pages([[{"type": "chart", "content": None}]])[0]++ assert isinstance(page.blocks[0], ChartBlock)+ assert page.blocks[0].content[0].type == "chart_body"+ assert page.blocks[0].content[0].content == ""+++def test_raw_title_levels_are_normalized_to_global_hierarchy() -> None:+ """验证 raw 标题在严格对象化前补齐全局一级和二级层级。"""+ page = model_list_to_pages(+ [+ [+ {"type": "doc_title", "content": "Document"},+ {"type": "paragraph_title", "content": "Section", "level": 1},+ ]+ ]+ )[0]++ assert [block.level for block in page.blocks] == [1, 2]def test_pdf_continuation_is_typed_and_line_metadata_is_removed() -> None:diff --git a/tests/unittest/test_postprocess_visual.py b/tests/unittest/test_postprocess_visual.pyindex 48f70eb1..3273c452 100644--- a/tests/unittest/test_postprocess_visual.py+++ b/tests/unittest/test_postprocess_visual.py@@ -291,12 +291,12 @@ def test_regroup_visual_blocks_preserves_dict_visual_metadata() -> None:assert "sub_type" not in table_block["content"][0]assert table_block["content"][0]["angle"] == 0assert table_block["content"][0]["score"] == 0.0- assert "cell_merge" not in table_block- assert table_block["content"][0]["cell_merge"] == [1, 0]+ assert table_block["cell_merge"] == [1, 0]+ assert "cell_merge" not in table_block["content"][0]-def test_regroup_visual_blocks_keeps_cell_merge_on_dict_body() -> None:- """验证 raw dict 表格的 cell_merge 只保留在 table body。"""+def test_regroup_visual_blocks_lifts_cell_merge_to_table() -> None:+ """验证 raw dict 表体的 cell_merge 上浮到 table 根块。"""table_body = {"index": 0,"type": BlockType.TABLE_BODY,@@ -309,9 +309,9 @@ def test_regroup_visual_blocks_keeps_cell_merge_on_dict_body() -> None:assert unmatched_blocks == []table_block = grouped_blocks[BlockType.TABLE][0]- assert "cell_merge" not in table_block+ assert table_block["cell_merge"] == [1, 0]assert len(table_block["content"]) == 1- assert table_block["content"][0]["cell_merge"] == [1, 0]+ assert "cell_merge" not in table_block["content"][0]def test_regroup_visual_blocks_without_bbox_prefers_previous_parent() -> None:diff --git a/tests/unittest/test_table_merge.py b/tests/unittest/test_table_merge.pyindex 288d4eb3..dab250d7 100644--- a/tests/unittest/test_table_merge.py+++ b/tests/unittest/test_table_merge.py@@ -18,7 +18,6 @@ def _table_body(*,index: int = 0,bbox: list[float] | None = None,- cell_merge: list[int] | None = None,) -> dict[str, Any]:"""构造归一化 bbox 的 table body 测试块。"""body: dict[str, Any] = {@@ -27,8 +26,6 @@ def _table_body("bbox": deepcopy(bbox or [0.1, 0.1, 0.9, 0.9]),"content": html,}- if cell_merge is not None:- body["cell_merge"] = cell_mergereturn body@@ -71,14 +68,16 @@ def _table(html,index=index,bbox=table_bbox,- cell_merge=cell_merge,)- return {+ table = {"type": BlockType.TABLE,"index": index,"bbox": table_bbox,"content": children if children is not None else [body],}+ if cell_merge is not None:+ table["cell_merge"] = cell_merge+ return tabledef _page(page_idx: int, blocks: list[dict[str, Any]]) -> dict[str, Any]:diff --git a/tests/unittest/test_table_merge_cell_merge.py b/tests/unittest/test_table_merge_cell_merge.pyindex 4d5f5f30..13c8badd 100644--- a/tests/unittest/test_table_merge_cell_merge.py+++ b/tests/unittest/test_table_merge_cell_merge.py@@ -17,14 +17,15 @@ def _build_table_block(index: int, html: str, cell_merge: list[int] | None = Non"bbox": [0.1, 0.1, 0.9, 0.9],"content": html,}- if cell_merge is not None:- body["cell_merge"] = cell_merge- return {+ table = {"index": index,"type": BlockType.TABLE,"bbox": [0.1, 0.1, 0.9, 0.9],"content": [body],}+ if cell_merge is not None:+ table["cell_merge"] = cell_merge+ return tabledef _row_texts(table: dict[str, Any]) -> list[list[str]]:@@ -34,7 +35,7 @@ def _row_texts(table: dict[str, Any]) -> list[list[str]]:return [[cell.get_text() for cell in row.find_all(["td", "th"])] for row in soup.find_all("tr")]-def test_merge_table_content_applies_partial_cell_merge_from_table_body() -> None:+def test_merge_table_content_applies_partial_cell_merge_from_table() -> None:"""验证部分视觉列续接后保留当前首行并清空已迁移单元格。"""previous_table = _build_table_block(0,