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: remove HTML support from parsers and related components to streamline file handling
myhlolieef881aa287b
diff --git a/mineru/__init__.py b/mineru/__init__.pyindex 8f3a4f6f..8dd46cec 100644--- a/mineru/__init__.py+++ b/mineru/__init__.py@@ -2,7 +2,6 @@from .parser import ( # noqa: F401DocumentParser,DocxParser,- HtmlParser,MinerUApiParser,ParseResult,PdfFlashParser,@@ -19,7 +18,6 @@ __all__ = ["Block","DocumentParser","DocxParser",- "HtmlParser","Line","MinerUApiParser","PageInfo",diff --git a/mineru/cli/commands/search.py b/mineru/cli/commands/search.pyindex 5fdd063c..5604787a 100644--- a/mineru/cli/commands/search.py+++ b/mineru/cli/commands/search.py@@ -10,8 +10,8 @@ from ...types import Tierfrom ..contracts import CliContextfrom ..runtime import run_cli-FILE_TYPES = "pdf, image, docx, pptx, xlsx, html, markdown, csv, rst, tex, txt"-FILE_EXTS = "pdf, png, jpg, jpeg, jp2, webp, gif, bmp, tiff, docx, pptx, xlsx, html, htm, md, markdown, csv, rst, tex, txt"+FILE_TYPES = "pdf, image, docx, pptx, xlsx, markdown, csv, rst, tex, txt"+FILE_EXTS = "pdf, png, jpg, jpeg, jp2, webp, gif, bmp, tiff, docx, pptx, xlsx, md, markdown, csv, rst, tex, txt"def search_cmd(diff --git a/mineru/doclib/constants.py b/mineru/doclib/constants.pyindex 7b80aed2..033ad5b3 100644--- a/mineru/doclib/constants.py+++ b/mineru/doclib/constants.py@@ -41,8 +41,6 @@ TEXT_EXTENSIONS: set[str] = {DISCOVERABLE_EXTENSIONS: set[str] = {"pdf",*OFFICE_EXTENSIONS,- "html",- "htm",*TEXT_EXTENSIONS,# Unsupported legacy Office formats:# "doc",diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.pyindex 62eca52c..7c7b47c9 100644--- a/mineru/doclib/services/parse_svc.py+++ b/mineru/doclib/services/parse_svc.py@@ -67,8 +67,6 @@ FTS_HEAD_HALF = 15_000DOC_TYPE_BY_EXT = {"md": "markdown","markdown": "markdown",- "htm": "html",- "html": "html",**dict.fromkeys(IMAGE_EXTENSIONS, "image"),}diff --git a/mineru/kit/common.py b/mineru/kit/common.pyindex dd5ffd1b..3635898b 100644--- a/mineru/kit/common.py+++ b/mineru/kit/common.py@@ -30,8 +30,6 @@ SUPPORTED_SUFFIXES = {".docx",".pptx",".xlsx",- ".html",- ".htm",}OUTPUT_FILE_SUFFIXES = {"markdown": ".md",diff --git a/mineru/parser/__init__.py b/mineru/parser/__init__.pyindex aeed9651..3882d59d 100644--- a/mineru/parser/__init__.py+++ b/mineru/parser/__init__.py@@ -4,20 +4,18 @@ from __future__ import annotationsfrom pathlib import Pathfrom ..types import Tier+from ..utils.backend_options import DEFAULT_HYBRID_EFFORTfrom .api_client import MinerUApiParserfrom .base import MIDDLE_JSON_SCHEMA_VERSION, DocumentParser, ParseResult-from .html import HtmlParserfrom .office import DocxParser, PptxParser, XlsxParserfrom .pdf import PdfFlashParser, PdfHybridParser, PdfPipelineParser, PdfVlmParserfrom .tier import PARSER_BACKENDS, backend_for_tier, resolve_runtime_options, resolve_tier_and_backend-from ..utils.backend_options import DEFAULT_HYBRID_EFFORT__all__ = ["backend_for_tier","PARSER_BACKENDS","DocumentParser","DocxParser",- "HtmlParser","MinerUApiParser","MIDDLE_JSON_SCHEMA_VERSION","ParseResult",@@ -33,9 +31,8 @@ __all__ = []_OFFICE_SUFFIXES = frozenset({"docx", "pptx", "xlsx"})-_HTML_SUFFIXES = frozenset({"html", "htm"})_PDF_INPUT_SUFFIXES = frozenset({"pdf", "png", "jpeg", "jp2", "webp", "gif", "bmp", "jpg", "tiff"})-_PATH_PRIORITY_SUFFIXES = _OFFICE_SUFFIXES | _HTML_SUFFIXES | _PDF_INPUT_SUFFIXES+_PATH_PRIORITY_SUFFIXES = _OFFICE_SUFFIXES | _PDF_INPUT_SUFFIXESdef _resolve_input_suffix(path: Path) -> str:@@ -76,8 +73,6 @@ def _build_parser("xlsx": XlsxParser,}[suffix]return parser_cls()- elif suffix in _HTML_SUFFIXES:- return HtmlParser()if suffix not in _PDF_INPUT_SUFFIXES:raise ValueError(f"Unsupported file type: {suffix or path.suffix or 'unknown'}")diff --git a/mineru/parser/api_client.py b/mineru/parser/api_client.pyindex 77c008f0..e9bfb3ab 100644--- a/mineru/parser/api_client.py+++ b/mineru/parser/api_client.py@@ -343,8 +343,6 @@ def _mime_type(path: Path) -> str:".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",- ".html": "text/html",- ".htm": "text/html",".png": "image/png",".jpg": "image/jpeg",".jpeg": "image/jpeg",diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.pyindex adbccf49..c77e9b2f 100644--- a/mineru/parser/api_server.py+++ b/mineru/parser/api_server.py@@ -1009,8 +1009,6 @@ _SUPPORTED_SUFFIXES: dict[str, str] = {".docx": "docx",".pptx": "pptx",".xlsx": "xlsx",- ".html": "html",- ".htm": "html",}_OUTPUT_FORMATS_LOCAL = set(_LOCAL_PARSE_OUTPUT_FORMATS)diff --git a/mineru/parser/html.py b/mineru/parser/html.pydeleted file mode 100644index bd681716..00000000--- a/mineru/parser/html.py+++ /dev/null@@ -1,192 +0,0 @@-# Copyright (c) Opendatalab. All rights reserved.-from __future__ import annotations--from pathlib import Path--from bs4 import BeautifulSoup, Tag--from .base import DocumentParser, ParseResult-from ..types import EMPTY_BBOX, Block, Line, PageInfo, Span-from ..utils.image_payload import ImagePayloadCache---class HtmlParser(DocumentParser):- """Parse HTML files into structured ``ParseResult``.-- HTML elements are mapped to typed blocks inside a single page.- """-- def parse(self, path: str | Path, *, page_range: str = "") -> ParseResult:- path = Path(path)- if not path.exists():- raise FileNotFoundError(path)-- html_text = path.read_text(encoding="utf-8")- soup = BeautifulSoup(html_text, "html.parser")-- body = soup.body or soup- blocks: list[Block] = []- image_cache = ImagePayloadCache()- _walk_elements(body, blocks, image_cache)- _assign_block_indexes(blocks)-- return ParseResult(- pages=[PageInfo(page_idx=0, para_blocks=blocks)],- _image_cache=image_cache,- )---_HEADING_TAGS = frozenset({"h1", "h2", "h3", "h4", "h5", "h6"})-_BLOCK_CONTAINER_TAGS = frozenset({- "div", "section", "article", "aside", "main", "header", "footer", "nav",-})---def _heading_level(tag_name: str) -> int:- return int(tag_name[1])---def _extract_text(element: Tag) -> str:- return element.get_text(separator=" ", strip=True)---def _find_image_element(element: Tag) -> Tag | None:- """查找 HTML 图片节点;当前元素本身是 img 时不能只搜索后代节点。"""- if element.name == "img":- return element- return element.find("img")---def _assign_block_indexes(blocks: list[Block]) -> None:- """递归补齐 HTML 解析产生的局部顺序号,保证 middle_json block 契约稳定。"""- for index, block in enumerate(blocks):- block.index = index- _assign_block_indexes(block.blocks)---def _line_with_spans(spans: list[Span]) -> Line:- """HTML 没有页面坐标,统一使用 EMPTY_BBOX 表示未知行框。"""- return Line(bbox=EMPTY_BBOX, spans=spans)---def _build_span(element: Tag, image_cache: ImagePayloadCache) -> Span:- content = _extract_text(element)- img = _find_image_element(element)- if img is not None:- src: str = img.get("src", "") or ""- if src.startswith("data:image"):- return Span(type="image", bbox=EMPTY_BBOX, image_path=image_cache.register_data_uri(src), content=content)- return Span(type="image", bbox=EMPTY_BBOX, image_path=src, content=content)- return Span(type="text", bbox=EMPTY_BBOX, content=content)---def _append_block(blocks: list[Block], block: Block) -> None:- block.index = len(blocks)- blocks.append(block)---def _walk_elements(parent: Tag, blocks: list[Block], image_cache: ImagePayloadCache) -> None: # type: ignore[type-arg]- for child in parent.children:- if not isinstance(child, Tag):- text = str(child).strip()- if text:- _append_block(blocks, Block(- index=0,- type="text",- bbox=EMPTY_BBOX,- lines=[_line_with_spans([Span(type="text", bbox=EMPTY_BBOX, content=text)])],- ))- continue-- tag_name = child.name-- if tag_name in _HEADING_TAGS:- _append_block(blocks, _build_heading(child, image_cache))- elif tag_name in ("p", "span"):- _append_block(blocks, _build_text_block(child, image_cache))- elif tag_name in _BLOCK_CONTAINER_TAGS:- _walk_elements(child, blocks, image_cache)- elif tag_name in ("ul", "ol"):- _append_block(blocks, _build_list(child, image_cache))- elif tag_name == "table":- _append_block(blocks, _build_table(child, image_cache))- elif tag_name == "pre":- _append_block(blocks, _build_code(child))- elif tag_name in ("img",):- _append_block(blocks, _build_image_block(child, image_cache))- elif tag_name in ("br",):- pass- else:- # fallback: treat unknown inline tags as text- if child.get_text(strip=True):- _append_block(blocks, _build_text_block(child, image_cache))---def _build_heading(element: Tag, image_cache: ImagePayloadCache) -> Block:- level = _heading_level(element.name)- return Block(- index=0,- type="title",- bbox=EMPTY_BBOX,- level=level,- lines=[_line_with_spans([_build_span(element, image_cache)])],- )---def _build_text_block(element: Tag, image_cache: ImagePayloadCache) -> Block:- # Collapse nested inline children into a single span.- return Block(- index=0,- type="text",- bbox=EMPTY_BBOX,- lines=[_line_with_spans([_build_span(element, image_cache)])],- )---def _build_image_block(element: Tag, image_cache: ImagePayloadCache) -> Block:- span = _build_span(element, image_cache)- return Block(- index=0,- type="image",- bbox=EMPTY_BBOX,- lines=[_line_with_spans([span])],- )---def _build_list(element: Tag, image_cache: ImagePayloadCache) -> Block:- items: list[Block] = []- for li in element.find_all("li", recursive=False):- nested_blocks: list[Block] = []- _walk_elements(li, nested_blocks, image_cache)- items.append(Block(- index=len(items),- type="list_item",- bbox=EMPTY_BBOX,- lines=[_line_with_spans([Span(type="text", bbox=EMPTY_BBOX, content=_extract_text(li))])],- blocks=nested_blocks,- ))- return Block(index=0, type="list", bbox=EMPTY_BBOX, blocks=items)---def _build_table(element: Tag, image_cache: ImagePayloadCache) -> Block:- return Block(- index=0,- type="table",- bbox=EMPTY_BBOX,- lines=[- _line_with_spans(- [Span(type="table", bbox=EMPTY_BBOX, content=image_cache.replace_html_data_uri_sources(str(element)))]- )- ],- )---def _build_code(element: Tag) -> Block:- code = element.find("code")- content = _extract_text(code) if code else _extract_text(element)- return Block(- index=0,- type="code",- bbox=EMPTY_BBOX,- lines=[_line_with_spans([Span(type="code", bbox=EMPTY_BBOX, content=content)])],- )