Skip to content

fix: keep NBSP instead of collapsing it like ASCII whitespace (#87) - #88

Open
bvandrc wants to merge 4 commits into
crosstype:masterfrom
bvandrc:fix/preserve-nbsp
Open

bvandrc wants to merge 4 commits into
crosstype:masterfrom
bvandrc:fix/preserve-nbsp

Conversation

@bvandrc

@bvandrc bvandrc commented Oct 27, 2026 •

Copy link
Copy Markdown

Fixes #87

Text collapsed with \s, which in JavaScript includes U+00A0, so   runs came out as a single space. HTML only collapses ASCII whitespace, and NBSP exists to not be collapsed.

  • processText collapses [ \t\n\f\r]+ instead of \s+
  • a text node counts as whitespace-only by the same set, rather than node-html-parser's isWhitespace, which includes NBSP and  
  • tagSurround keeps an edge whitespace run whole when it holds NBSP, instead of only the one character next to the content

Claude-Session: https://claude.ai/code/session_018xDzwbcJFd3dMc24MCMT5W

…ype#87)

Text collapsed with `\s`, which in JavaScript includes U+00A0, so ` `
runs came out as a single space. HTML only collapses ASCII whitespace, and
NBSP exists to not be collapsed.

- processText collapses `[ \t\n\f\r]+` instead of `\s+`
- a text node counts as whitespace-only by the same set, rather than
  node-html-parser's `isWhitespace`, which includes NBSP and ` `
- tagSurround keeps an edge whitespace run whole when it holds NBSP,
  instead of only the one character next to the content

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018xDzwbcJFd3dMc24MCMT5W
Comment thread src/utilities.ts Resolved
Comment thread src/visitor.ts Resolved
…hitespace

Mirrors node-html-parser's isWhitespace getter, which the visitor used before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WcmVi7QkUu1TeYUfXMN5n
…patching TextNode

Patching node-html-parser's prototype changed it for every importer in the process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WcmVi7QkUu1TeYUfXMN5n
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.

bug: NBSP is collapsed like ordinary whitespace

2 participants