Skip to content

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

fix: validate inline HTML wire formulas

myhloli90851d4d134a
diff --git a/CLAUDE.md b/CLAUDE.md
index d3026bc4..647cc31f 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -169,7 +169,7 @@ pr-5415 重构后,Middle JSON 已收敛为 schema 2.0 的统一结构,不再
### 1. 统一分析入口
-`backend/analyze.py:doc_analyze()` 是 PDF、EPUB、CSV 与 Office 文档的唯一公共入口,通过 `file_suffix` 路由到 `backend/analysis/pdf/pipeline.py:analyze_pdf`、`backend/analysis/epub.py:analyze_epub`、`backend/analysis/csv.py:analyze_csv` 或 `backend/analysis/office.py:analyze_office`,最终经 `backend/postprocess/pages.py:model_list_to_pages()` 产出统一 `pages`。`MinerUParser` 是 `DocumentParser` 的唯一实现,替代旧的 `PdfHybridParser`/`PdfFlashParser`/`DocxParser` 等。
+`backend/analyze.py:doc_analyze()` 是 PDF、EPUB、HTML、CSV 与 Office 文档的唯一公共入口,通过 `file_suffix` 路由到 `backend/analysis/pdf/pipeline.py:analyze_pdf`、`backend/analysis/epub.py:analyze_epub`、`backend/analysis/html.py:analyze_html`、`backend/analysis/csv.py:analyze_csv` 或 `backend/analysis/office.py:analyze_office`,最终经 `backend/postprocess/pages.py:model_list_to_pages()` 产出统一 `pages`。`MinerUParser` 是 `DocumentParser` 的唯一实现,替代旧的 `PdfHybridParser`/`PdfFlashParser`/`DocxParser` 等。
### 2. MiddleJson 顶层字段(schema 2.0)
@@ -179,7 +179,7 @@ pr-5415 重构后,Middle JSON 已收敛为 schema 2.0 的统一结构,不再
|------|------|------|
| `pages` | `list[PageInfo]` | 严格按 `page_idx` 升序的页面数组 |
| `is_full_document` | `bool` | 是否整本文档解析(空 `page_index_map` 时为 `True`) |
-| `file_suffix` | `Literal["pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "rtf", "csv", "epub", "odt", "ods", "odp"]` | 输入文件类型 |
+| `file_suffix` | `Literal["pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "rtf", "csv", "epub", "html", "odt", "ods", "odp"]` | 输入文件类型 |
| `effort` | `Literal["flash", "medium", "high", "xhigh"]` | 分析强度 |
| `parse_mode` | `Literal["txt", "ocr"]` | 解析模式 |
| `mineru_version` | `str` | MinerU 版本号 |
diff --git a/mineru/model/flash/html/wire.py b/mineru/model/flash/html/wire.py
index 86c543c1..a8cde63c 100644
--- a/mineru/model/flash/html/wire.py
+++ b/mineru/model/flash/html/wire.py
@@ -292,7 +292,7 @@ def _validate_simple_content(content_root: etree._Element, block_type: BlockType
continue
if marker_type != BlockType.EQUATION:
raise _WireValidationError("invalid_nested_marker")
- _validate_formula_carrier(marker, expected_display=None)
+ _validate_formula_carrier(marker, expected_display="inline")
def _validate_equation_content(content_root: etree._Element) -> None:
@@ -345,7 +345,7 @@ def _validate_visual_content(content_root: etree._Element, wrapper: etree._Eleme
continue
if (marker.get("data-block-type") or "").strip() != BlockType.EQUATION:
raise _WireValidationError("invalid_visual_nested_marker")
- _validate_formula_carrier(marker, expected_display=None)
+ _validate_formula_carrier(marker, expected_display="inline")
else:
if local_name(child) != "p":
raise _WireValidationError("invalid_annotation_shape")
@@ -354,7 +354,7 @@ def _validate_visual_content(content_root: etree._Element, wrapper: etree._Eleme
continue
if (marker.get("data-block-type") or "").strip() != BlockType.EQUATION:
raise _WireValidationError("invalid_annotation_nested_marker")
- _validate_formula_carrier(marker, expected_display=None)
+ _validate_formula_carrier(marker, expected_display="inline")
def _validate_list_container(container: etree._Element, *, top_wrapper: etree._Element | None = None) -> None:
@@ -386,7 +386,7 @@ def _validate_list_container(container: etree._Element, *, top_wrapper: etree._E
continue
if marker_type != BlockType.EQUATION:
raise _WireValidationError("invalid_list_nested_marker")
- _validate_formula_carrier(marker, expected_display=None)
+ _validate_formula_carrier(marker, expected_display="inline")
elif not nested_lists:
raise _WireValidationError("markerless_list_leaf")
for nested in nested_lists:
@@ -435,7 +435,7 @@ def _validate_index_list(container: etree._Element, *, nested: bool) -> None:
continue
if marker_type != BlockType.EQUATION:
raise _WireValidationError("invalid_index_nested_marker")
- _validate_formula_carrier(marker, expected_display=None)
+ _validate_formula_carrier(marker, expected_display="inline")
elif not nested_lists:
raise _WireValidationError("markerless_index_leaf")
for child in nested_lists:
diff --git a/tests/unittest/test_flash_html.py b/tests/unittest/test_flash_html.py
index 074ecd81..fcb8454b 100644
--- a/tests/unittest/test_flash_html.py
+++ b/tests/unittest/test_flash_html.py
@@ -900,7 +900,7 @@ def test_html_invalid_versioned_markers_fallback_without_partial_results() -> No
{
"page_idx": 0,
"blocks": [
- {"type": "text", "index": 0, "content": "WIRESENTINEL"},
+ {"type": "text", "index": 0, "content": "WIRESENTINEL <eq>WIREFORMULA</eq>"},
{
"type": "image",
"index": 1,
@@ -948,9 +948,16 @@ def test_html_invalid_versioned_markers_fallback_without_partial_results() -> No
parent_mismatch.select_one('[data-block-type="image_caption"]')["data-block-type"] = "table_caption"
variants.append(str(parent_mismatch))
+ block_nested_formula = BeautifulSoup(base, "html.parser")
+ block_nested_formula.select_one('[data-block-type="equation"][data-formula-display="inline"]')["data-formula-display"] = (
+ "block"
+ )
+ variants.append(str(block_nested_formula))
+
for variant in variants:
markdown = render_markdown(doc_analyze(variant.encode(), file_suffix="html")[0])
assert markdown.count("WIRESENTINEL") == 1
+ assert markdown.count("WIREFORMULA") == 1
assert markdown.count("Visible caption") == 1