Skip to content

fix(pdf): keep wrapped PDF table cells in their rows - #85

Merged
asionesjia merged 2 commits into
mainfrom
fix/pdf-table-structure
Aug 26, 2026
Merged

asionesjia merged 2 commits into
mainfrom
fix/pdf-table-structure

Conversation

@asionesjia

@asionesjia asionesjia commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Confirmed against the opendataloader-bench pages in #75. Cell assignment in packages/pdf/src/tables.ts dropped short row rules and treated wrapped lines as new rows, so headers leaked, multi-line cells split, and one grid became several GFM tables.

Changes

  • Keep gridlines down to 12pt so short ruled rows still join the grid
  • Add outer column edges from horizontal rules, and fall back to text rows when a grid has columns but only a top/bottom rule
  • Fold wrapped continuation lines into the current row by column bands (not nearest column center)
  • Allow one long text column so comparison grids with Y/N plus restriction paragraphs stay one table

Checks

  • 01030000000081: TABLE 22 header and the wrapped Food Safety row stay in one 3-column table
  • 01030000000045 / 46: org/party names and counts stay in columns
  • 01030000000088–90: country, Y/N, and restriction text stay in one grid
  • Corpus pdf/text.pdf snapshot unchanged
  • bun test and bun run lint pass

fixes #75


Note

Medium Risk
Heuristic changes in table detection may mis-classify some PDF layouts (false tables or merged prose), though scope is limited to markdown output from packages/pdf.

Overview
Fixes PDF table extraction where wrapped text and partial ruling were split into extra rows or multiple GFM tables instead of one grid.

Ruled grids: lowers minimum rule length (MIN_RULE 24→12), extends column edges from horizontal rule extents, and when there are columns but fewer than two row bands, falls back to buildTextGrid (aligned-text folding) instead of rejecting the grid. Bounds use vertical rule extents where relevant.

Borderless / aligned tables: extends row runs with isContinuation (column alignment, caption skip, wrap span), then foldRows merges continuation lines into the current logical row via column bands (columnIndex / edges) and startsRow heuristics (keys, totals, lowercase wraps). Column inference is split into inferColumns + finishAlignedTable. acceptGrid and acceptBorderless are relaxed so one long column and larger tables (higher word/row limits) can still pass—e.g. Y/N plus restriction paragraphs stay one table.

Adds regression tests for short vertical rules, wrapped headers/cells, two-column wraps, and multi-column GATS-style grids.

Reviewed by Cursor Bugbot for commit 0b59ab7. Bugbot is set up for automated code reviews on this repo. Configure here.

Short row rules were dropped (MIN_RULE 24pt), so wrapped cells
split across GFM tables and headers leaked as body text. Fold
continuation lines into column bands, keep short gridlines, and
assign cells by edges instead of column centers.

fixes #75
@asionesjia asionesjia added bug Something isn't working pkg:pdf @mdgate/pdf labels Aug 26, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
mdgate-demo 0b59ab7 Aug 26 2026, 07:48 AM

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Two-column wrap detection fails
    • inferColumns now divides matching two-column rows by full.length so wrap lines no longer dilute the 0.5 threshold.
  • ✅ Fixed: Short wraps split table rows
    • startsRow now folds a single-column wrap into a cell that already has text, so short capitalized suffixes stay in the same row.

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 188cffd. Configure here.

Comment thread packages/pdf/src/tables.ts
Comment thread packages/pdf/src/tables.ts

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Left a non-blocking comment and did not approve. Cursor Bugbot was present, then skipped, and its review still reports 2 unresolved medium-severity findings that need human attention. No reviewers were assigned because the only assignable user is the PR author.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

Score two-column consistency against full rows only so wrap lines
do not drop the table. Fold a single-column wrap into a cell that
already has text, including short proper-noun and suffix lines.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved. Cursor Bugbot passed on this head with no unresolved findings that need human review. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

@asionesjia
asionesjia merged commit 0d64c81 into main Aug 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pkg:pdf @mdgate/pdf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF: tables lose row and column structure

2 participants