Skip to content

to_markdown/to_json: opt-in table_output="html" backed by the PyMuPDF core table model - #440

Closed
veget-able wants to merge 1 commit into
pymupdf:mainfrom
veget-able:table-output-html
Closed

to_markdown/to_json: opt-in table_output="html" backed by the PyMuPDF core table model#440
veget-able wants to merge 1 commit into
pymupdf:mainfrom
veget-able:table-output-html

Conversation

@veget-able

Copy link
Copy Markdown
Contributor

Adds table_output="html" to to_markdown() and to_json(). With it, the layout path keeps reading order, body text and OCR handling unchanged, and only the table rendering switches to reconstructed HTML <table> elements — merged cells (colspan/rowspan) and multi-row headers preserved, driven by the core model from the companion PyMuPDF PR (find_tables(use_layout=True, union=True, refine=True), Table.placements, Table.to_html()).

The integration layer is deliberately thin (~178 lines in helpers/table_html/): one find_tables call per page, payload assembly for reading order / body-text exclusion / to_json grid fields, and a standalone to_html() convenience. A README section documents the option.

Depends on pymupdf/PyMuPDF#5057 — the helpers call pymupdf.table APIs introduced there; CI here will not pass until that lands in a released build.

Measured (ParseBench table group, 503 pages, GTRM): 56.73 official → 72.11 with both PRs and the opt-in enabled. Without table_output="html" nothing changes: non-opt-in output is byte-identical to the official build (verified by output hashing), and the kwarg matches the official signature's silent-ignore behavior on older PyMuPDF.

Tests: tests/test_table_html.py added (opt-in routing, HTML structure, to_json grid consistency, no-layout fallback, body-text no-loss).

… model

Adds table_output="html" to to_markdown() and to_json(). When set, the
layout path keeps reading order, body text and OCR handling unchanged
and only the table rendering switches to reconstructed HTML <table>
elements -- merged cells (colspan/rowspan) and multi-row headers
preserved -- driven by the core model of the companion PyMuPDF change
(find_tables(use_layout=True, union=True, refine=True),
Table.placements, Table.to_html()).

The integration layer is helpers/table_html/ (~180 lines): one
find_tables call per page, payload assembly for reading order,
body-text exclusion and to_json grid fields, and a standalone to_html()
convenience. A README section documents the option.

Without the opt-in, output is byte-identical to the current build
(verified by output hashing); on older PyMuPDF the kwarg keeps the
official signature's silent-ignore behavior. On ParseBench's table
group (503 pages, GTRM) the official stack scores 56.73 and the
opted-in stack scores 72.11 together with the companion PyMuPDF change,
on which this depends. Adds tests/test_table_html.py.
@veget-able

Copy link
Copy Markdown
Contributor Author

Superseded by #441 ? same commit, moved from the fork to an in-org branch so the workflow has access to the aptest secret (per Julian). Closing in favor of #441.

@veget-able veget-able closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant