Skip to content

An HTML table keeps its caption - #1287

Merged
WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/html-table-keeps-its-caption
Oct 16, 2026
Merged

WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/html-table-keeps-its-caption

Conversation

@Maya-Kid

Copy link
Copy Markdown
Contributor

table::lift_tables replaces each rendered table with a placeholder and grid() reads only row cells, so <caption> is lost.

Problem

On dev 6e09e58, html::fragment_to_markdown reads

<table><caption>Readings by well</caption>
<tr><th>Well</th><th>Depth</th></tr><tr><td>North</td><td>1200</td></tr></table>

as the bare table. Every HTML path lifts tables: .html files, feeds, linked articles, MinerU tables. Extraction's table rules take a table's subject and unit from its caption.

Change

  • render_table writes the caption as a paragraph before the table, adding no colon. The chunker repeats it in every piece of a split table if at most 200 bytes or ending in a colon.
  • Captions starting like a heading, list, quote or code fence (# of wells, ~~~ Notes) are escaped, as htmd does.
  • page_to_markdown looks for the page title in htmd's text before tables return, so a lifted table never suppresses # title, on pages without a caption too: on dev a title row, header or cell repeating the title did, and every chunk lost the title breadcrumb.

Verification

Limits

  • Readability (dom_smoothie 0.16) flattens a captioned table that is a page's main content, caption lost, as on dev.
  • A title row repeating the caption appears twice.
  • A caption over 200 bytes without a final colon is written once, and a lead-in above it no longer repeats in the table's pieces; one above several captioned tables now reaches only the first.

Signed-off-by: dada-yan <BinjunYann@gmail.com>

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Writing the <caption> as its own paragraph without a colon is right: short captions go with every piece of the table, and long ones are written once instead of filling each piece. Checking the page title before the tables come back keeps a caption like "Pricing tiers" from removing # Pricing from every chunk's breadcrumb. Two small follow-ups: the title-row caption in render_rows has the same # of wells problem and could also use as_paragraph, and the escaping test could keep one input per branch (-/+/*, the two fences and 1./2) each share one). Merging.

@WaylandYang
WaylandYang merged commit cd1d58a into deeplethe:dev Oct 16, 2026
6 checks passed
@Maya-Kid
Maya-Kid deleted the fix/html-table-keeps-its-caption branch October 16, 2026 23:29
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.

2 participants