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
Closed
to_markdown/to_json: opt-in table_output="html" backed by the PyMuPDF core table model#440veget-able wants to merge 1 commit into
veget-able wants to merge 1 commit into
Conversation
… 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.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
table_output="html"toto_markdown()andto_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/): onefind_tablescall per page, payload assembly for reading order / body-text exclusion /to_jsongrid fields, and a standaloneto_html()convenience. A README section documents the option.Depends on pymupdf/PyMuPDF#5057 — the helpers call
pymupdf.tableAPIs 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.pyadded (opt-in routing, HTML structure, to_json grid consistency, no-layout fallback, body-text no-loss).