Safely remove repeating whitespace from HTML text.
\sto normalize HTML whitespace will strip out characters that are actually rendered by a web browser. Such would be classified as a lossy change and would produce a different visual result. This package will collapse multiple whitespace characters down to a single space, while ignoring the following characters:
(zero-width non-breaking space)
…as well as these lesser-known ones:
(Mongolian vowel separator)
For the sake of completeness, the following characters which are not part of
\swill also not be affected:
(zero-width breaking space)
Note: this package does not contain an HTML parser. It is meant to be used on text nodes only.
>= 8is required. Type this at the command line:
npm install normalize-html-whitespace
const normalizeWhitespace = require('normalize-html-whitespace'); normalizeWhitespace(' foo bar baz '); //-> ' foo bar baz '