PDF: line-final hyphen is removed before a capitalized word (non-Hodgkin becomes nonHodgkin)

Open
#5,584 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@kushdab is already working on this.

Since Nov 26, 2026.

  • #5593 by @kushdab — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend, data

Research direction

Read PageAssembleModel.sanitize_text in docling/models/stages/page_assemble/page_assemble_model.py and the regression cases in tests/test_page_assemble_model.py. Run those tests to check the lowercase-before-capital case and the mixed-case and uppercase cases. The issue describes the expected output; an open linked pull request (#5593) already covers this work.

Written by the indexing model from the issue text.

Description

bug pdf priority:medium

Summary

When a PDF line ends with a hyphen after a lowercase word and the next line starts with a capital letter, PageAssembleModel.sanitize_text deletes the hyphen and joins the two halves. Compounds with a proper noun or acronym become wrong words: "non-Hodgkin lymphoma" becomes "nonHodgkin lymphoma", "anti-American" becomes "antiAmerican", "pre-COVID" becomes "preCOVID".

Users cannot get the hyphen back from the output, and a search for the correct term fails. This is the same class of problem as #4151 and #5492. ReadingOrderModel._merge_elements already joins across clusters only when the continuation is lowercase, so the two places now disagree.

Reproduction

Run on current main (0521b433):

from docling.models.stages.page_assemble.page_assemble_model import PageAssembleModel, PageAssembleOptions

m = PageAssembleModel(PageAssembleOptions())
for lines in (["patients with non-", "Hodgkin lymphoma"], ["the anti-", "American campaign"],
              ["before the pre-", "COVID period"], ["new algo-", "rithms"], ["the INFOR-", "MATION"]):
    print(lines, "->", repr(m.sanitize_text(list(lines))))

Actual

['patients with non-', 'Hodgkin lymphoma'] -> 'patients with nonHodgkin lymphoma'
['the anti-', 'American campaign'] -> 'the antiAmerican campaign'
['before the pre-', 'COVID period'] -> 'before the preCOVID period'
['new algo-', 'rithms'] -> 'new algorithms'
['the INFOR-', 'MATION'] -> 'the INFORMATION'

Expected

'patients with non-Hodgkin lymphoma'
'the anti-American campaign'
'before the pre-COVID period'
'new algorithms'        (unchanged)
'the INFORMATION'       (unchanged)

Cause

sanitize_text keeps an attached line-final hyphen only for a few special cases (a single-character token, a digit continuation, an uppercase abbreviation before a lowercase continuation, from #4387 and #5498). In every other case it removes the hyphen and joins. A hyphenation break almost never puts a capital letter after an all-lowercase word, but this case is not handled.

Proposed fix

Add one more keep-rule: the whole word before the hyphen is lowercase and the continuation starts with an uppercase letter. The rule is deliberately narrow. A mixed-case word split before a capital, such as TeX breaking "Table-|Former", "PubTab-|Net" or "Java-|Script" (these breaks occur in docling's own test PDFs 2203.01017v2 and 2305.03393v1), still joins into "TableFormer" / "JavaScript". "algo-|rithms" and "INFOR-|MATION" behave as now.

There are regression tests (positive and negative) in tests/test_page_assemble_model.py. I scanned the CI PDF sources: the only breaks that match the narrow rule are artifacts from text in different columns, and none of them is joined in the groundtruth, so no e2e groundtruth should change. I could not run the e2e conversion locally (no models), so CI should confirm this.

I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.

I've tested a fix with a regression test: https://github.com/chaitanya0305/docling/compare/main...chaitanya0305:docling:fix/keep-hyphen-before-capitalized. If this is accepted, I'll open the PR straight away.

Dominant language
Python
Stars
71k
Forks
5.4k
Avg merge
2d 22h
Merged PRs (30d)
161

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docling-project/docling

All issues in docling-project/docling

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.