From bded4edf47dad93037d9db8825551d8dd879b425 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Aug 2026 20:55:20 +0000 Subject: [PATCH 1/2] fix(sdui-parser): keep the space between a text run and an adjacent sibling element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `parseChildren` collapsed each text run's whitespace to a single space — correct, that is HTML's own whitespace model — and then `.trim()`ed it, which is not: HTML collapses a whitespace run to ONE space, it does not delete it. The deleted space is the one that separates a run from an adjacent inline sibling, so every authored sentence with emphasis or a link in the `kind:'html'` tier rendered with its words run together: `A x page` came out as `Axpage`. Keep one leading space when a sibling precedes the run and one trailing space when a sibling element follows it; the parent's own start/end still drop theirs. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01EuPCi56cnGyykygi3z9w4m --- .../src/__tests__/inline-whitespace.test.tsx | 189 ++++++++++++++++++ packages/sdui-parser/src/parse.ts | 25 ++- 2 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 packages/sdui-parser/src/__tests__/inline-whitespace.test.tsx diff --git a/packages/sdui-parser/src/__tests__/inline-whitespace.test.tsx b/packages/sdui-parser/src/__tests__/inline-whitespace.test.tsx new file mode 100644 index 0000000000..4724ab1729 --- /dev/null +++ b/packages/sdui-parser/src/__tests__/inline-whitespace.test.tsx @@ -0,0 +1,189 @@ +/** + * objectui#5661 — the space between a text run and an adjacent inline element. + * + * ## The defect + * + * `parseChildren` collapsed each text run's whitespace to a single space (right + * — that is HTML's own whitespace model) and then `.trim()`ed it (wrong — HTML + * collapses a whitespace run to ONE space, it does not delete it). The deleted + * space is exactly the one separating a run from an adjacent inline sibling, so + * the tier the guide recommends by default rendered every emphasised sentence + * with its words run together, silently: + * + * A kind:'html' page -> "A" "page" -> Akind:'html'page + * + * ## The rule pinned here (triage decision, option (b)) + * + * Collapse the run, then keep ONE leading space only when a sibling precedes + * the run, and ONE trailing space only when a sibling ELEMENT follows it. At + * the parent's own start/end the edge space is still dropped. Deliberately + * mechanical: it invents no block/inline taxonomy for a schema tree that has + * none (that was the rejected option (a)). + * + * Its known cost is bounded and pinned below: a whitespace-only run BETWEEN two + * siblings survives as a single space, so a pretty-printed `