Suggestion: Normalize HTML/XML entities
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Often, when consuming HTML or XML files from external sources, it's desirable to normalize the entities. For example, I'm interacting with an API that produces XML where all non-ASCII characters are encoded as numbered entities, making non-Latin-script text completely unreadable. I want to debug and store these files in a format that's human-readable _as well as_ machine-readable, while remaining valid UTF-8 XML.
**Describe the solution you'd like**
Currently, [html/entities](https://github.com/denoland/deno_std/blob/main/html/entities.ts) exports `escape` and `unescape` functions. I suggest exporting a third function (tentatively named `normalize`) that normalizes all entities in a string of HTML or XML to a form that's valid, interoperable, and (mostly) human-readable:
```ts
normalize('
两只小蜜蜂
') // '两只小蜜蜂
'normalize('a&b') // 'a&b'
normalize('>>>') // '>>>'
normalize(''') // '''
```
**Describe alternatives you've considered**
It might be worth having multiple normalized forms (which would likely also affect the API surface area of `escape`); for example, a "readability" form that converts `两只小蜜蜂` to `两只小蜜蜂` vs a "compatibility" form that converts in the opposite direction. I don't currently have a use case for the "compatibility" form as any XML-consuming APIs I need to interact with either default to UTF-8 or respect UTF-8 where specified, but it might be useful for users needing to interact with legacy or poorly-designed APIs.
Contributor guide
Assessment
This issue has not been assessed yet.