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
Handle table span content in markdown renderer
jinzhenjadff444c8a83
diff --git a/mineru/render/markdown.py b/mineru/render/markdown.pyindex c1d3f06c..9c8a9b69 100644--- a/mineru/render/markdown.py+++ b/mineru/render/markdown.py@@ -1,7 +1,7 @@from ..types import Block, BlockType, ContentType+from .markdown_table import to_markdown_tablefrom .merge import merge_para_textfrom .merge_visual import _build_media_path, merge_visual_para_text-from .markdown_table import to_markdown_tabledef blocks_to_markdown(@@ -97,11 +97,8 @@ def _build_image_link(block: Block, target_span_type: str, img_bucket_path: str)def _render_table_block_as_markdown_table(para_block: Block, img_bucket_path: str) -> str:- rendered = merge_visual_para_text(para_block, img_bucket_path)for span in para_block.all_spans():if span.type != ContentType.TABLE or not span.content:continue- candidate = to_markdown_table(span.content)- if candidate != span.content.strip():- return candidate- return rendered+ return to_markdown_table(span.content)+ return merge_visual_para_text(para_block, img_bucket_path)diff --git a/tests/unittest/test_render_html_table.py b/tests/unittest/test_render_html_table.pyindex 4b32637b..26d36e62 100644--- a/tests/unittest/test_render_html_table.py+++ b/tests/unittest/test_render_html_table.py@@ -207,3 +207,37 @@ def test_render_markdown_prefers_markdown_table_when_enabled() -> None:"| Alice | 90 |",])+++def test_blocks_to_markdown_prefers_table_content_without_html_attribute() -> None:+ html = """+ <table>+ <tr><th>Page</th><th>Status</th></tr>+ <tr><td>10</td><td>ready</td></tr>+ </table>+ """.strip()+ table_span = Span(type=ContentType.TABLE, bbox=(0.0, 0.0, 10.0, 10.0), content=html)+ table_block = Block(+ index=0,+ type=BlockType.TABLE,+ bbox=(0.0, 0.0, 10.0, 10.0),+ blocks=[+ Block(+ index=0,+ type=BlockType.TABLE_BODY,+ bbox=(0.0, 0.0, 10.0, 10.0),+ lines=[Line(bbox=(0.0, 0.0, 10.0, 10.0), spans=[table_span])],+ )+ ],+ )++ assert not hasattr(table_span, "html")+ assert blocks_to_markdown([table_block], prefer_markdown_table=True) == [+ "\n".join(+ [+ "| Page | Status |",+ "| --- | --- |",+ "| 10 | ready |",+ ]+ )+ ]