Skip to content

Reading-order hard-hyphen continuations retain an inserted space #3886

Description

@Success6666

Bug

ReadingOrderModel._merge_elements removes a trailing soft hyphen (\u00ad) before joining a cross-element continuation, but a hard hyphen (-) always follows the regular space-joining path. A split word such as algo- + rithms is therefore emitted as algo- rithms.

Steps to reproduce

The affected code path is deterministic with two TextElement instances carrying the same label:

  1. Create a list item whose text is algo-.
  2. Merge a following LIST_ITEM element whose text is rithms.
  3. ReadingOrderModel._merge_elements(...) produces algo- rithms instead of algorithms.

Soft hyphens already produce algorithms, which makes the hard-hyphen behavior inconsistent.

Expected behavior

When the first element ends in - and the first non-whitespace character of the continuation is lowercase, treat the pair as a hyphenated line wrap: remove the hyphen and join without a space. Preserve the existing behavior for uppercase continuations, where a hard hyphen may be meaningful punctuation.

Docling version

main at 873f990 (package version 2.115.0).

Python version

Python 3.13.12.

Relationship to #3881

This is the downstream half of #3881. A companion change in docling-ibm-models makes eligible LIST_ITEM pairs reach the merge mapping; this change ensures the final document text is correctly dehyphenated once that mapping is present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions