fix(pdf): preserve a line-final hyphen that does not split a word (#4043) - #4052
Open
VSathveek wants to merge 1 commit into
Open
fix(pdf): preserve a line-final hyphen that does not split a word (#4043)#4052VSathveek wants to merge 1 commit into
VSathveek wants to merge 1 commit into
Conversation
…cling-project#4043) Signed-off-by: Varanasi Sathveek <sathveekvaranasi@gmail.com>
Contributor
|
✅ DCO Check Passed Thanks @VSathveek, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
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.
Issue resolved by this Pull Request:
Resolves #4043
Problem
PageAssembleModel.sanitize_text()drops a line-final hyphen before joining twolines, assuming it is a hyphen that splits a word across the break. The guard
deciding this inspects the last word token anywhere in the line rather than
the hyphen itself:
\b[\w]+\bskips over whitespace, so for a line ending... -pn 1 -the last tokenis
"1", the guard passes, and the hyphen is deleted even though it was neverattached to a word. The wrap reported in the issue is therefore extracted as
... -pn 1 prio 3 ..., the flag silently losing its dash.The deletion is not specific to CLI syntax. Any line-final hyphen that follows
whitespace is affected, and the existing test corpus turns out to contain four
such documents where a real character is being discarded today.
Fix
Only a hyphen attached to the preceding word marks a split word, so the fix
requires the character immediately before it to be alphanumeric:
That condition only ever narrows the existing one, so nothing de-hyphenated
today stops being de-hyphenated:
"algo-"+"rithms"→"algorithms"isunchanged, as is the existing exclusion of underscore-bearing tokens
(
"foo_bar-"+"baz"stays"foo_bar-baz").A detached hyphen is then treated as what it is — an ordinary character that
happens to sit at a line break — so it is kept and the lines are joined with a
space, exactly as the non-hyphen branch already does.
Reference data
Four documents change. Three recover a character that is being discarded today:
redp5110_sampledimproves structurally. Four bullet items whose-marker satalone on its own cell were glued to the following word, which pushed them out of
the list and into numbered entries; they are now recognised as list items:
One line moves sideways rather than forwards, and I would rather point at it than
let it pass unnoticed. In
2305.03393v1the author ORCIDs arrive as separatecells (
"[0000","-","0002", ...), so the bare hyphens now take a space:Neither form is the real
[0000-0002-3723-6960]; the identifier is alreadybroken upstream by the per-cell split and the space this branch adds between
cells. No character is gained or lost, so I left it rather than special-casing
digits, but it is the one diff here that is not an improvement.
I ran the suite against unmodified
mainfirst to confirm this environmentreproduces the committed reference data exactly, so these diffs are attributable
to the change and not to local drift. Flagging them for the double review the
contributing guide asks for.
A limitation worth stating
Whether a detached hyphen should close up against the next token (
-prio) orkeep its space (
- ECCV) is not decidable at this layer: the caller.strip()seach cell before
sanitize_textsees it, so the trailing-space evidence isalready gone. All four corpus cases are separator dashes wanting the space, so
that is the default here, and the issue's flag case comes out as
-pn 1 - prio 3— the dash preserved but not closed up. That fixes the data loss the issue is
about without inventing a distinction the input no longer carries. Recovering it
properly means keeping the pre-strip whitespace, which is a larger change to the
caller and I would rather not fold it in here.
Tests
TestSanitizeTextHyphenationintests/test_page_assemble_model.pycovers bothdirections: an attached hyphen still joins a split word, a non-alphanumeric
token is still left alone, and detached hyphens (wrapped flag, separator dash,
bullet marker, negative number) are preserved. The detached cases fail on
main.One related spot, left alone deliberately
ReadingOrderModel._merge_elementshas a parallel end-of-line hyphen check formerging elements across cluster boundaries and drops a detached hyphen the same
way. I have not touched it here, since the module has other work in flight
(#3891, #3955). Happy to follow up separately, or to fold it in if you prefer.
Checklist: