From 8a6340f6330249cfbe9da662fdef36b2e778e535 Mon Sep 17 00:00:00 2001 From: berce <75228263+bercedev@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:28:11 +0000 Subject: [PATCH] fix(cli): count a contraction as one word in line_unread (#6346) WORD_RUNS split at apostrophes, so "can't" counted as two words and a line with contractions got a longer hold floor than its real word count. Refs #6338 --- packages/cli/src/utils/craftAudit.test.ts | 6 ++++++ packages/cli/src/utils/craftAudit.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/utils/craftAudit.test.ts b/packages/cli/src/utils/craftAudit.test.ts index a1d8242e1a..25ed3ac5ff 100644 --- a/packages/cli/src/utils/craftAudit.test.ts +++ b/packages/cli/src/utils/craftAudit.test.ts @@ -81,6 +81,12 @@ describe("readingWords", () => { expect(readingWords("✓ — →")).toBe(0); expect(readingWords("今天天气很好")).toBeGreaterThan(1); }); + + it("counts a contraction as one word", () => { + expect(readingWords("a tooth can't get in")).toBe(5); + expect(readingWords("a tooth can’t get in")).toBe(5); + expect(readingWords("it's 'quoted'")).toBe(2); + }); }); describe("lineFloorSec", () => { diff --git a/packages/cli/src/utils/craftAudit.ts b/packages/cli/src/utils/craftAudit.ts index c76ed90484..b2456f64d5 100644 --- a/packages/cli/src/utils/craftAudit.ts +++ b/packages/cli/src/utils/craftAudit.ts @@ -29,7 +29,7 @@ const CRAFT_THRESHOLDS = { const T = CRAFT_THRESHOLDS; const ZERO_BBOX: CheckBbox = { x: 0, y: 0, width: 0, height: 0 }; -const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+/gu; +const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+(?:['’][\p{L}\p{M}\p{N}]+)*/gu; // Chinese and Japanese have no spaces; a dictionary segmenter counts their words like an English line's. const WORD_SEGMENTER = new Intl.Segmenter("ja", { granularity: "word" });