Keep the space a whitespace-only span puts between two words - #119
Merged
Merged
Conversation
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 as <span typeof="mw:Entity"> </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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wikipedia's HTML writes every
as<span typeof="mw:Entity"> </span>, and oc glued the words on either side of it.oc wiki article "Python_(programming_language)":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.6millionandJanuary 20, 2009–January 20, 2017, which the page shows with spaces.Cause. A text fragment remembers whether space touched its edges (
pre/post), somergeTextcan glue the pieces a parser split out of one word and put a space between the rest. Indistill'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
poston 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.jsgains one test with three shapes: the infobox label and date above, andten<b> </b>items. Onmainit fails withFirstappeared,20February 1991,tenitems. No fixture page intests/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