Decode HTML entities in JavaScript?

后端 未结 3 1574
情深已故
情深已故 2020-11-27 07:00

Sample conversions:

 & -> `&`
 >  -> `>`

Any small library function that can handle this?

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 07:32

    A robust HTML entity encoder/decoder written in JavaScript.

    https://mths.be/he

    he (for “HTML entities”) is a robust HTML entity encoder/decoder written in JavaScript. It supports all standardized named character references as per HTML, handles ambiguous ampersands and other edge cases just like a browser would, has an extensive test suite, and — contrary to many other JavaScript solutions — he handles astral Unicode symbols just fine. An online demo is available.

提交回复
热议问题