Skip to content

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

feat: extend file type registry with tsv/shtml and more text extensions

jinzhenje05073b785e2
diff --git a/mineru/filetypes.py b/mineru/filetypes.py
index c4dbcb1d..828d1368 100644
--- a/mineru/filetypes.py
+++ b/mineru/filetypes.py
@@ -1,7 +1,7 @@
from __future__ import annotations
-from pathlib import Path
import re
+from pathlib import Path
from typing import Final
from .types import QUALITY_TIERS, Tier, validate_tier
@@ -17,6 +17,13 @@ from .types import QUALITY_TIERS, Tier, validate_tier
# Unsupported mail formats:
# "eml",
# "mbox",
+# Other doc formats:
+# "djvu/djv"
+# "epdf",
+# "xps",
+# "ps",
+# "eps/epsi/epi"
+# "ept/ept2/ept3"
PDF_EXTENSIONS: frozenset[str] = frozenset({"pdf"})
@@ -30,11 +37,13 @@ OFD_EXTENSIONS: frozenset[str] = frozenset({"ofd"})
OFFICE_EXTENSIONS: frozenset[str] = frozenset({"doc", "docx", "ppt", "pptx", "xls", "xlsx", "rtf"}) | ODF_EXTENSIONS
-HTML_EXTENSIONS: frozenset[str] = frozenset({"html", "htm"})
+HTML_EXTENSIONS: frozenset[str] = frozenset({"html", "htm", "shtml"})
-CSV_EXTENSIONS: frozenset[str] = frozenset({"csv"})
+CSV_EXTENSIONS: frozenset[str] = frozenset({"csv", "tsv"})
-TEXT_EXTENSIONS: frozenset[str] = frozenset({"txt", "md", "markdown", "rst", "tex"})
+TEXT_EXTENSIONS: frozenset[str] = frozenset(
+ {"txt", "text", "ftxt", "md", "markdown", "mdx", "rst", "tex", "latex", "adoc", "asciidoc"}
+)
TIERED_PARSE_EXTENSIONS: frozenset[str] = PDF_EXTENSIONS | IMAGE_EXTENSIONS
@@ -61,10 +70,16 @@ FILE_TYPE_BY_EXTENSION: dict[str, str] = {
**dict.fromkeys(EPUB_EXTENSIONS, "epub"),
**dict.fromkeys(OFD_EXTENSIONS, "ofd"),
"txt": "text",
+ "text": "text",
+ "ftxt": "text",
"md": "markdown",
"markdown": "markdown",
+ "mdx": "markdown",
"rst": "rst",
"tex": "tex",
+ "latex": "tex",
+ "adoc": "asciidoc",
+ "asciidoc": "asciidoc",
}
TEXT_FILE_TYPES: frozenset[str] = frozenset(FILE_TYPE_BY_EXTENSION[ext] for ext in TEXT_EXTENSIONS)
@@ -82,11 +97,13 @@ MIME_TYPE_BY_EXTENSION: dict[str, str] = {
"ods": "application/vnd.oasis.opendocument.spreadsheet",
"odp": "application/vnd.oasis.opendocument.presentation",
"csv": "text/csv",
+ "tsv": "text/tab-separated-values",
"epub": "application/epub+zip",
# OFD 尚无 IANA 注册 subtype;使用生态中通行的项目级 MIME 映射。
"ofd": "application/ofd",
"html": "text/html",
"htm": "text/html",
+ "shtml": "text/html",
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
@@ -95,6 +112,17 @@ MIME_TYPE_BY_EXTENSION: dict[str, str] = {
"gif": "image/gif",
"bmp": "image/bmp",
"tiff": "image/tiff",
+ "txt": "text/plain",
+ "text": "text/plain",
+ "ftxt": "text/plain",
+ "md": "text/markdown",
+ "markdown": "text/markdown",
+ "mdx": "text/markdown",
+ "rst": "text/x-rst",
+ "tex": "text/x-tex",
+ "latex": "application/x-latex",
+ "adoc": "text/plain",
+ "asciidoc": "text/plain",
}
_RTF_HEADER_RE: Final = re.compile(
diff --git a/mineru/parser/file_type.py b/mineru/parser/file_type.py
index 6ba11be1..50967ed7 100644
--- a/mineru/parser/file_type.py
+++ b/mineru/parser/file_type.py
@@ -10,7 +10,7 @@ from zipfile import BadZipFile, ZipFile
from loguru import logger
from magika import Magika
-from ..filetypes import IMAGE_EXTENSIONS, rtf_header_offset
+from ..filetypes import CSV_EXTENSIONS, HTML_EXTENSIONS, IMAGE_EXTENSIONS, rtf_header_offset
PDF_SIG_BYTES = b"%PDF"
OLE2_SIG_BYTES = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1"
@@ -273,9 +273,9 @@ def _has_rtf_signature_by_path(file_path: Path) -> bool:
def _resolve_signatureless_csv_suffix(detected_suffix: str, file_path: str | Path | None) -> str:
- """仅以 .csv 扩展名兜底无签名文本,并保留强内容类型的优先级。"""
+ """以 .csv/.tsv 扩展名兜底无签名分隔文本,并保留强内容类型的优先级。"""
extension = Path(file_path).suffix.lower().lstrip(".") if file_path else ""
- if extension == "csv":
+ if extension in CSV_EXTENSIONS:
if detected_suffix in _STRONG_CONTENT_SUFFIXES:
return detected_suffix
return "csv"
@@ -287,9 +287,9 @@ def _resolve_signatureless_csv_suffix(detected_suffix: str, file_path: str | Pat
def _resolve_signatureless_html_suffix(detected_suffix: str, file_path: str | Path | None) -> str:
- """用 .html/.htm 兜底短文本,并把 Magika 的 HTML 结果统一规范为 html。"""
+ """用 HTML_EXTENSIONS 兜底短文本,并把 Magika 的 HTML 结果统一规范为 html。"""
extension = Path(file_path).suffix.lower().lstrip(".") if file_path else ""
- if extension in {"html", "htm"} and detected_suffix not in _STRONG_CONTENT_SUFFIXES:
+ if extension in HTML_EXTENSIONS and detected_suffix not in _STRONG_CONTENT_SUFFIXES:
return "html"
return "html" if detected_suffix == "html" else detected_suffix
diff --git a/tests/unittest/test_filetypes.py b/tests/unittest/test_filetypes.py
index 91284d0c..5634297d 100644
--- a/tests/unittest/test_filetypes.py
+++ b/tests/unittest/test_filetypes.py
@@ -97,15 +97,17 @@ def test_odf_extensions_are_flash_only_office_types() -> None:
def test_csv_is_a_flash_only_parseable_type_instead_of_plain_text() -> None:
- """验证 CSV 进入结构化 flash 解析集合并保留独立 MIME 和文件类型。"""
- assert CSV_EXTENSIONS == frozenset({"csv"})
- assert "csv" in FLASH_ONLY_PARSE_EXTENSIONS
- assert "csv" in PARSEABLE_EXTENSIONS
- assert "csv" in INGESTIBLE_EXTENSIONS
- assert "csv" not in TEXT_EXTENSIONS
- assert FILE_TYPE_BY_EXTENSION["csv"] == "csv"
+ """验证 CSV/TSV 进入结构化 flash 解析集合并保留独立 MIME 和文件类型。"""
+ assert CSV_EXTENSIONS == frozenset({"csv", "tsv"})
+ for ext in CSV_EXTENSIONS:
+ assert ext in FLASH_ONLY_PARSE_EXTENSIONS
+ assert ext in PARSEABLE_EXTENSIONS
+ assert ext in INGESTIBLE_EXTENSIONS
+ assert ext not in TEXT_EXTENSIONS
+ assert FILE_TYPE_BY_EXTENSION[ext] == "csv"
+ assert is_flash_only_parse_extension(ext)
assert MIME_TYPE_BY_EXTENSION["csv"] == "text/csv"
- assert is_flash_only_parse_extension("csv")
+ assert MIME_TYPE_BY_EXTENSION["tsv"] == "text/tab-separated-values"
def test_epub_is_a_flash_only_parseable_e_book_type() -> None:
@@ -122,7 +124,7 @@ def test_epub_is_a_flash_only_parseable_e_book_type() -> None:
def test_html_extensions_are_canonical_flash_only_inputs() -> None:
"""验证 HTML/HTM 在所有入口归一为单一 html 文件类型。"""
- assert HTML_EXTENSIONS == frozenset({"html", "htm"})
+ assert HTML_EXTENSIONS == frozenset({"html", "htm", "shtml"})
for ext in HTML_EXTENSIONS:
assert ext in FLASH_ONLY_PARSE_EXTENSIONS
assert ext in PARSEABLE_EXTENSIONS
@@ -144,6 +146,18 @@ def test_ofd_is_an_independent_fixed_layout_flash_type() -> None:
assert is_flash_only_parse_extension("ofd")
+def test_additional_text_extensions_are_ingestible_but_not_parseable() -> None:
+ """新增文本扩展进入 doclib ingest/扫描,但不进入结构化解析集合。"""
+ for ext in ("mdx", "latex", "adoc", "asciidoc"):
+ assert ext in TEXT_EXTENSIONS
+ assert ext in INGESTIBLE_EXTENSIONS
+ assert ext not in PARSEABLE_EXTENSIONS
+ assert FILE_TYPE_BY_EXTENSION["mdx"] == "markdown"
+ assert FILE_TYPE_BY_EXTENSION["latex"] == "tex"
+ assert FILE_TYPE_BY_EXTENSION["adoc"] == "asciidoc"
+ assert FILE_TYPE_BY_EXTENSION["asciidoc"] == "asciidoc"
+
+
def test_mineru_kit_discovers_and_accepts_csv_inputs(tmp_path: Path) -> None:
"""验证 mineru-kit 的目录展开和输入校验自动继承 CSV 解析集合。"""
csv_path = tmp_path / "sample.csv"