Skip to content

A non-breaking hyphen in a Word document is read as a hyphen, so the numbers on either side of it stay apart - #1031

Merged
WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/docx-non-breaking-hyphen
Oct 1, 2026
Merged

WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:fix/docx-non-breaking-hyphen

Conversation

@Maya-Kid

@Maya-Kid Maya-Kid commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Word writes a non-breaking hyphen as an element of its own, <w:noBreakHyphen/>, not as a character in w:t. People type it with Ctrl+Shift+-, and converters write it to keep "2024-01-15" or "010-62345678" on one line. docx_xml_to_text reads the text of w:t and the few elements that stand for a break or a tab. So the hyphen is dropped, and the numbers on either side of it run together.

Problem

A Word file written by python-docx, with non-breaking hyphens in a date and in a phone number, reads like this on dev 2e7ba78:

合同于 20240115 签订,联系电话 01062345678。

The page shows 2024‑01‑15 and 010‑62345678.

  • Time extraction no longer sees a date.
  • Search for either number finds nothing.

It is the same loss #813 fixed for breaks in table cells and #1019 fixed for breaks on slides.

Change

docx_xml_to_text writes <w:noBreakHyphen/> as a hyphen, in a paragraph and in a table cell, next to the w:tab case. It writes the ASCII hyphen-minus rather than U+2011, so "2024-01-15" reads as the date it is.

Verification

Run on macOS (arm64): Rust 1.98.1; the workspace suite against PostgreSQL 16 with pgvector 0.8.2, with Poppler 26.06.

  • a_non_breaking_hyphen_keeps_the_numbers_on_either_side_apart (crates/utopia-ingest/tests/docx_breaks.rs) covers a hyphen inside a run and one in a run of its own.
    • In a paragraph it gives 合同于 2024-01-15 签订,电话 010-62345678。.
    • In a table cell it gives | Sample | 2024-01-15 |.
    • On dev with only the test added, it fails: 合同于 20240115 签订,电话 01062345678。.
  • The python-docx file above reads 合同于 2024-01-15 签订,联系电话 010-62345678。.
  • cargo test --locked -p utopia-ingest: 124 passed.
  • cargo fmt --all --check and cargo clippy --locked --workspace --all-targets -- -D warnings are clean.
  • UTOPIA_TEST_REQUIRE_DB=1 UTOPIA_TEST_REQUIRE_PDFTOTEXT=1 cargo test --locked --workspace: 1,345 passed, 0 failed, 6 ignored. That run had this change merged with the spreadsheet-number fix opened alongside it.

…numbers on either side of it stay apart

Signed-off-by: dada-yan <BinjunYann@gmail.com>

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Thanks @Maya-Kid. Reviewed at 1eba5d1: w:noBreakHyphen is written as a plain hyphen in a paragraph and in a cell, so a date and a phone number keep their parts. The ASCII hyphen is the right choice over U+2011.

@WaylandYang
WaylandYang merged commit 6b0a1d7 into deeplethe:dev Oct 1, 2026
6 checks passed
@Maya-Kid
Maya-Kid deleted the fix/docx-non-breaking-hyphen branch October 15, 2026 03:29
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.

2 participants