Skip to content

Keep the space a whitespace-only span puts between two words - #119

Merged
only-cli merged 2 commits into
only-cli:mainfrom
kevin9327:fix/space-only-span-separates
Sep 28, 2026
Merged

only-cli merged 2 commits into
only-cli:mainfrom
kevin9327:fix/space-only-span-separates

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Wikipedia's HTML writes every &nbsp; as <span typeof="mw:Entity">&nbsp;</span>, and oc glued the words on either side of it. oc wiki article "Python_(programming_language)":

main:    Firstappeared
         20February 1991 ; 35 years ago
         ... Python3.0, released in 2008, was a major revision ...
         Python implementation began in December1989.
branch:  First appeared
         20 February 1991 ; 35 years ago
         ... Python 3.0, released in 2008, was a major revision ...
         Python implementation began in December 1989.

That is 43 of the article's 2,368 blocks. On the Barack Obama article it is 143 of 7,793 blocks, among them $1.6million and January 20, 2009–January 20, 2017, which the page shows with spaces.

Cause. A text fragment remembers whether space touched its edges (pre/post), so mergeText can glue the pieces a parser split out of one word and put a space between the rest. In distill's walk (src/distill.js), a text node that is only whitespace has no text once collapsed and was skipped without a trace. The fragments around the span share a parent and neither touches a space itself, so they looked like one word.

Change. A whitespace-only text node now sets post on the text block just before it, which is what it was on the page. If the last block is a break or not text, nothing changes. Nothing is added to the output except the missing spaces.

Test. tests/distill.test.js gains one test with three shapes: the infobox label and date above, and ten<b> </b>items. On main it fails with Firstappeared, 20February 1991, tenitems. No fixture page in tests/pages/ changes a single block. Full suite on Windows (Node 24): 316 tests, 313 pass, 3 skipped, 0 fail.

Left alone. A fragment in another element with no space between (1991<span>;</span>) is still joined with a space, as it was; that rule is not about whitespace nodes. No CHANGELOG line, to keep this round's PRs from conflicting there.

🤖 Generated with Claude Code

kevin9327 and others added 2 commits September 29, 2026 06:44
A text fragment remembers whether space touched its edges, so mergeText
can glue the pieces a parser split out of one word and space the rest.
A text node that is only whitespace was skipped without a trace, so the
fragments on either side of it looked adjacent and were glued.

Wikipedia's HTML writes every &nbsp; as <span typeof="mw:Entity">&nbsp;
</span>, and the text around it shares a parent, so the Python article
read "Firstappeared", "20February 1991", "Python3.0", and "December1989",
43 blocks in all.

A whitespace-only node now marks the text block before it as ending in
space, which is what it was on the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@only-cli
only-cli merged commit 44b64de into only-cli:main Sep 28, 2026
5 checks passed
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