Skip to content

fix(pdf): keep extractable chart labels out of broken tables - #86

Merged
asionesjia merged 2 commits into
mainfrom
fix/pdf-chart-labels
Aug 27, 2026
Merged

asionesjia merged 2 commits into
mainfrom
fix/pdf-chart-labels

Conversation

@asionesjia

@asionesjia asionesjia commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Confirmed #76: extractable chart text (pdftotext -layout already has it) was turned into broken tables, and axis/grid lines were tagged as underline/strike. Raster-only charts remain out of scope.

Changes

  • Skip rotated text in table detection so vertical date labels are not sliced into columns
  • Reject borderless grids that look like chart ticks, legends, date fragments, or side-by-side chart titles
  • Join rotated axis-label runs (01/2019 instead of 0 1/ 201 9) and adjacent numeric TJ fragments
  • Ignore stroke rules that run far past a glyph (chart axes) while keeping real word underlines

Real tables (ruled grids, named columns, year headers) still convert as markdown tables. Checked against the issue examples: categories, years, dates, and scores stay as text instead of empty-cell tables.

fixes #76


Note

Medium Risk
Changes core PDF-to-markdown heuristics for tables, line joining, and underline detection; regressions could drop real tables or alter formatting on edge-case PDFs, but behavior is heavily test-backed.

Overview
Chart and axis text in PDFs was being misread as markdown tables and decorated with false underline/strike from long grid lines. This PR tightens table detection and text assembly so those layouts stay plain text while real tables still convert.

Table detection exports isUpright from layout and ignores rotated glyphs when building ruled and borderless grids. Borderless acceptance adds several chart-shaped rejectors (stacked date fragments, category+year legends, scattered bar values, percent rows with category ticks, numeric scatter without real headers, and similar junk). Prose-heavy multi-column grids are filtered a bit more aggressively.

Markdown extraction runs a new mergeNumericFragments pass after script merging so TJ-split percents and nearby numeric shards become single tokens. shouldJoinItems uses orientation: upright runs still use horizontal gaps; rotated runs can join by proximity. Underline/strike matching skips horizontal rules that extend far beyond the text width (typical chart baselines) while keeping short rules under real words.

Regression tests cover chart ticks, rotated dates, split percents, and that legitimate tables (year headers, Q columns, percent summaries, ruled matrices) are unchanged.

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

Chart ticks, bar values, and legends were detected as tables, and axis
gridlines were marked as underline/strike. Skip rotated items in table
detection, reject chart-like grids, join rotated date labels, and ignore
rules that run far past a glyph.

fixes #76
@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 c04205f Aug 26 2026, 01:08 PM

@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 high effort and found 3 potential issues.

Fix All in Cursor

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

  • ✅ Fixed: Percent tables rejected as ticks
    • looksLikeLabeledTicks now rejects only when a percent/numeric row appears above the category labels, so header-first percent summary tables are kept.
  • ✅ Fixed: Digit headers marked as junk
    • looksLikeHeaderlessJunk now keeps two-row grids whose header cells are mostly lettered tokens such as Q1 or 1st.
  • ✅ Fixed: Numeric grids treated as dates
    • looksLikeDateFragments now requires a slash in the grid, so short all-numeric matrices are no longer treated as date junk.

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

Reviewed by Cursor Bugbot for commit 0e9f24b. Configure here.

Comment thread packages/pdf/src/tables.ts
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. Cursor Bugbot finished as skipped and reported 3 unresolved issues, so this is not approved. No reviewers were assigned. Human review is needed.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

Chart-junk checks were dropping ordinary summary tables, Q1-style
headers, and ruled numeric matrices.

@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 the current head, and the earlier findings are resolved. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

@asionesjia
asionesjia merged commit cff66d6 into main Aug 27, 2026
7 checks passed
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.

PDF: extractable chart labels are dropped or turned into broken tables

2 participants