Détail du package

string-fix-broken-named-entities

codsen3.4kMIT7.0.20

Finds and fixes common and not so common broken named HTML entities, returns ranges array of fixes

broken, encoding, entities, erroneous

readme

string-fix-broken-named-entities

Finds and fixes common and not so common broken named HTML entities, returns ranges array of fixes

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 5.4.0 (npm i string-fix-broken-named-entities@5.4.0).

npm i string-fix-broken-named-entities

Quick Take

import { strict as assert } from "assert";
import { rApply } from "ranges-apply";

import { fixEnt } from "string-fix-broken-named-entities";

const source = "&nsp;x&nsp;y&nsp;";

// returns Ranges notation, see codsen.com/ranges/
assert.deepEqual(fixEnt(source), [
  [0, 5, " "],
  [6, 11, " "],
  [12, 17, " "],
]);

// render result from ranges using "ranges-apply":
assert.equal(rApply(source, fixEnt(source)), " x y ");

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2025 Roy Revelt and other contributors.

ok codsen star

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

7.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

6.1.0 (2022-08-12)

Features

6.0.15 (2022-05-04)

Fixed

6.0.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

5.4.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

5.3.0 (2021-04-11)

Features

  • export the array of all possibly-reported rule names, allRules (7e16a96)

Reverts

  • Revert "chore: setup refresh" (23cf206)

5.2.0 (2021-03-25)

Features

  • improve the matching algorithm when there are competing fixing choices (ce43906)

5.1.0 (2021-03-23)

Fixed

  • fix a case with entity without semi, reporting of raw amps in front (8e25561)
  • more fixes for opts.textAmpersandCatcherCb (1bbdf3a)
  • tend a falsy opts.cb (8626c30)
  • tweaks for opts.textAmpersandCatcherCb (18d4805)

Features

  • opts.textAmpersandCatcherCb and tweak rule names to conform to emlint better (27f2518)

5.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

5.0.0 (2021-01-23)

Features

  • rewrite in TS, start using named exports (13b81a3)

BREAKING CHANGES

  • previously you'd consume like: import fixEnt from ... - now import { fixEnt } from ...

4.0.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

3.0.0 (2020-05-06)

Fixed

  • measure distance on more lenient Levenshtein l=2 by source entity which is present (afb99d6)

Features

  • big refactor, levenshtein on all entities, more tests (671dd5e)

BREAKING CHANGES

  • less of crazy nbsp cases will be covered, essentially nbsp's from now on are like all other entities - treated the same

3.0.0

Rebase.

Previously, the   detection was more sophisticated than the rest of the entities'. We were using a home-brew analogue of Levenshtein's distance but tuned to all the possible and impossible peculiarities of fat-finger cases.

It was impossible to scale the algorithm to all other entities.

We re-coded all the logic to use Levenshtein distance — for all entities, including nbsp — and removed all the DIY Levenshtein clauses of nbsp

API doesn't change but we bump major because the code has been changed drastically and in theory that opens new opportunities to bugs.

But all existing unit tests pass and more have been added.

2.6.0 (2020-04-26)

Features

  • add more eslint rules and make them pass, rebase a little as well (6e5e19f)

2.5.0 (2019-11-21)

Features

  • release opts.entityCatcherCb - change it to ping only healthy entities + documentation (d7a76b2)

2.4.3 (2019-09-11)

Fixed

  • algorithm tweaks (fe71a2a)
  • treat clean nbsp sequences correctly (061de0d)

2.4.0 (2019-08-24)

Fixed

  • fix &prnsim to be recognised correctly (fd4df75)
  • further named entity recognition fixes (feef62b)
  • recognise false positive &nspar and also wire up false-positive array to be checked (c5d2d2d)

Features

  • improved recognition of joined named html entities without semicolons (4aa96f7)

2.3.0 (2019-06-01)

Features

  • Algorithm improvements and more unit tests (23d8596)
  • Avoid false positives when adding missing ampersand onto named HTML entities (5b48388)
  • Loosen amp fixes when ampersand is present (49238ff)
  • Make fixing algorithm more conservative, tap the list of uncertain entities (1806c12)
  • Move the known adhoc broken entity patterns above all-entity matching part (c9350fa)
  • opts.entityCatcherCb (cb77ae9)
  • Programmatic tests to cover entity letter case errors and making them pass (f3dc471)
  • Supports numeric entities, both decimal and hex (d07d5c4)
  • wrong case and whitespace recognition on all named HTML entities (942d2cf)

2.2.0 (2019-04-06)

Fixed

  • Align nbsp missing semicol error with other entities, use -malformed-nbsp (12420e5)
  • Before recoding missing semicolon check part (ad3394f)
  • Checks for all named HTML entities, missing ampersands or semicolon recognition (7762556)
  • Full support of all named HTML entities - missing semicolons or ampersands (c0b92c5)
  • Rebase to use all-named-html-entities instead of plain list array of entities (434945a)
  • Rudimentary protection against CSS false positive display:block (8c14b90)
  • Separate numeric entities for releases later (1942303)

2.1.0 (2019-03-17)

Fixed

  • Properly recognise false cases for double-encoded entity scenarios (0b3eed2)

Features

  • Algorithm improvements (daa1149)
  • Improvements to recognise malformed entities and multiple encoding (1ef1698)

2.0.0 (2019-03-04)

Features

  • Make opts.progressFn + opts.decode combo to be more precise (f599a29)
  • Add opts.cb (8f34d1c)
  • Add opts.progressFn (869e3f0)

1.6.0 (2019-01-27)

1.4.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

1.1.0 (2018-10-25)

  • Update all dependencies
  • Restore coveralls.io reporting
  • Restore unit test linting

1.0.0 (2018-08-29)

  • First public release