fix(pdf): recover drop-caps, ligatures, and TJ word spaces - #88
Merged
Merged
Conversation
Map Differences glyph names with the AGL suffix and ligature rules, glue drop-caps onto the first overlapping body line, and insert spaces from large negative TJ adjustments. Do not treat body-sized isolated lines as headings. fixes #78
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
mdgate-demo | b3a6c7e | Aug 27 2026, 06:05 AM |
There was a problem hiding this comment.
Security review of added/modified lines found no MEDIUM or higher issues with verified exploitability. Glyph-name mapping, drop-cap merge, and TJ spacing stay inside untrusted-PDF-to-Markdown conversion and do not cross a privilege or sandbox boundary.
Sent by Cursor Security Agent: Security Reviewer
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Drop-cap glues onto the wrong line
- findDropCapTarget now rejects body lines beyond a max x distance and prefers the nearest column so a higher right-column or farther run no longer receives the drop-cap.
You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 9f6dcfb. Configure here.
Select the nearest body line within a max x distance so a higher right-column or farther run does not receive the letter.
4 tasks done
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.



Summary
Confirmed #78 against the cited opendataloader-bench pages. Three separate PDF text bugs were producing the reported output.
/Differencesnames such asf_i,T_h,eight.oldstyle, andt.scwere looked up as raw AGL keys, so ligatures and small-caps vanished (field→eld,THIS COLLECTION OF SIXmissing).headerLevelused that letter's size, soT/Ibecame headings and the rest of the word (his report,ndia suffers) was left behind.uni00A0) or as a large negative TJ adjustment (-250,-1000) were not turned into Markdown spaces (as ayoung,SOLAR10.7B,1Introduction).Changes
uniXXXXrules, expandfi/flligatures, and treat NBSP as a space.Test plan
bunx vitest run packages/pdf/testbun run lintbun test(547 pass)Note
Medium Risk
Changes core PDF text extraction and markdown structure heuristics; regressions could affect heading levels, spacing, and ligature decoding across many documents, though behavior is covered by expanded vitest cases.
Overview
Improves PDF-to-Markdown text recovery for encoding, layout, and heading heuristics that were mangling real documents.
Glyph names (
glyphNameToUnicode) now follow AGL-style rules: strip period suffixes, split on_, resolveuniXXXX/uXXXX, expand Latin ligature presentation forms, and uppercase small-cap suffixes (t.sc→T). Invisible cleanup normalizes NBSP and similar width spaces to ordinary spaces and expands ligature code points in decoded strings.Drop caps are detected as oversized single letters and reattached to the overlapping body line (with guards for multi-column and misplaced targets), so output reads
This report…instead of a# Theading plushis report…. Line grouping uses a slightly looser vertical tolerance when merging runs on the same row.TJ spacing: large negative adjustments (≥ ~0.12 em) insert a space between adjacent text runs, fixing glued tokens like
SOLAR10.7Band1Introduction.Heading detection measures each line’s body font size (not the first run), estimates document body size from character mass (so footnote-heavy pages don’t skew base size), tightens false-heading cues (e.g. trailing comma), and skips very short isolated lines—reducing false
#headings on wrapped body and drop-cap artifacts while keeping real titles like “Executive Summary”.Reviewed by Cursor Bugbot for commit b3a6c7e. Bugbot is set up for automated code reviews on this repo. Configure here.