Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docreader/parser/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

# File types that builtin does not implement natively. When the requested
# engine (including empty / builtin) cannot parse them, route to this engine
# instead of raising ValueError — PPT/PPTX/CSV are markitdown-only.
# instead of raising ValueError — PPT/PPTX/CSV/SQL are markitdown-only.
_DEFAULT_ENGINE_BY_TYPE = {
"ppt": "markitdown",
"pptx": "markitdown",
"csv": "markitdown",
"sql": "markitdown",
}


Expand Down Expand Up @@ -191,6 +192,7 @@ def _build_default_registry() -> ParserEngineRegistry:
"xlsx": MarkitdownParser,
"xls": MarkitdownParser,
"csv": MarkitdownParser,
"sql": MarkitdownParser,
},
description="MarkItDown 解析引擎(微软 MarkItDown 库)",
)
Expand Down
22 changes: 21 additions & 1 deletion docreader/tests/test_parser_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ def test_empty_engine_routes_pptx_to_markitdown(self):
self.assertIs(registry.get_parser_class("", "ppt"), MarkitdownParser)
self.assertIs(registry.get_parser_class("", ".PPTX"), MarkitdownParser)

def test_empty_engine_routes_sql_to_markitdown(self):
self.assertIs(registry.get_parser_class("", "sql"), MarkitdownParser)
self.assertIs(registry.get_parser_class(BUILTIN_ENGINE, ".SQL"), MarkitdownParser)

def test_sql_file_is_parsed_as_text(self):
result = Parser().parse_file(
"schema.sql",
"sql",
b"-- marker\nSELECT 1 AS marker;\n",
)

self.assertIn("SELECT 1 AS marker;", result.content)

def test_builtin_engine_still_parses_pptx(self):
self.assertIs(registry.get_parser_class(BUILTIN_ENGINE, "pptx"), MarkitdownParser)

Expand All @@ -75,13 +88,20 @@ def test_type_default_when_builtin_lacks_pptx(self):
isolated.register(BUILTIN_ENGINE, {"pdf": PDFParser})
isolated.register(
"markitdown",
{"pptx": MarkitdownParser, "ppt": MarkitdownParser, "csv": MarkitdownParser},
{
"pptx": MarkitdownParser,
"ppt": MarkitdownParser,
"csv": MarkitdownParser,
"sql": MarkitdownParser,
},
)

self.assertIs(isolated.get_parser_class("", "pptx"), MarkitdownParser)
self.assertIs(isolated.get_parser_class(BUILTIN_ENGINE, "pptx"), MarkitdownParser)
self.assertIs(isolated.get_parser_class("", "csv"), MarkitdownParser)
self.assertIs(isolated.get_parser_class(BUILTIN_ENGINE, "csv"), MarkitdownParser)
self.assertIs(isolated.get_parser_class("", "sql"), MarkitdownParser)
self.assertIs(isolated.get_parser_class(BUILTIN_ENGINE, "sql"), MarkitdownParser)
self.assertIs(isolated.get_parser_class(BUILTIN_ENGINE, "pdf"), PDFParser)
self.assertIs(isolated.get_parser_class("", "pdf"), PDFParser)

Expand Down