HTML import trims the space at inline element boundaries, so words run together (<strong>Focus: </strong>Text → Focus:Text)
Summary
The HTML importer trims the whitespace at the edges of inline elements and bare text nodes, so words on either side of an inline boundary run together in the published page. Browsers collapse whitespace but keep one space at an inline boundary; the importer drops it.
Steps to reproduce
- Paste HTML or run Site Import with:
<p><strong>Focus: </strong>Controlling pain and swelling.</p> <p>Ask your <a href="/faq">surgeon</a> about recovery.</p> <p>Read the <em>important </em>safety information.</p> - Publish and view the page or its source.
Expected behavior
The text reads as in the source: "Focus: Controlling pain…", "Ask your surgeon about recovery.", "Read the important safety information." Runs of whitespace collapse to one space, but the space at each inline boundary is kept, either in the inline element or in the neighbouring text node.
Actual behavior
- Observed: the published HTML has
<strong>Focus:</strong>Controlling pain…, which renders as "Focus:Controlling". - Not yet verified: the
<a>and<em>lines are the same pattern (a boundary space at the start or end of a text node). I expect them to fail the same way, because the code path below trims every text node, but I've only reproduced the<strong>case.
The cause appears to be normalizeImportedText in src/core/htmlImport/text.ts:
return raw.replace(/\s+/g, ' ').trim()
rules.ts uses it for an element's text prop (text: normalizeImportedText(el.textContent ?? '')), and walkAndMap.ts uses it for bare text nodes. The .trim() suits block-level text, where leading and trailing whitespace isn't rendered, but not text inside or next to inline elements in mixed content. A possible fix:
- keep the collapse (
/\s+/g→' '), but trim only at the edges of a block's content, not per inline node; or - keep a single leading or trailing space when the node has an inline sibling on that side.
Why it matters
It silently changes published copy. We found it on a medical-device patient site, where the wording of regulated text has to match the approved source. A site-wide content check flagged "Focus:Controlling" on a recovery page; the source HTML has the space.
Version or commit
0.0.20 (f92e8dc). src/core/htmlImport/text.ts is unchanged on main at 0.0.21 (d1abbef).
Deployment mode
Local, bun run start (SQLite), Bun 1.4.2, macOS