xmlunidefuse
Encode the predefined XML entities (amp, lt, gt, apos, quot)
and some additional, easily overlooked Unicode characters.
Opt-out CharRef 39 for HTML (Why?).
Usage
From test.js:
var xud = require("xmlunidefuse"), eq = require("assert").strictEqual,
raw = "<!-- <u snow=\"man'>☃</u -->";
eq(xud(raw), // HTML compat mode: v..
"<​!-- <u snow="man'>☃</u -->");
eq(xud.apos(raw), // apos opt-in: v...
"<​!-- <u snow="man'>☃</u -->");
// CDATA mode is implemented but not recommended,
// because it makes the sneaky chars VERY visible.
eq(xud.cdata(raw),
'<![CDATA[<]]>​<![CDATA[!-- <u]]> <![CDATA[snow="ma' +
"n'>☃</u]]> <![CDATA[-->]]>");
Related
- univeil:
Unveil sneaky Unicode characters.
- xmldefuse:
Encode only the predefined XML entities.
- xmldecode:
Decode the predefined XML entities, CharRefs and CDATA sections.
License
ISC