Naively encoding characters using 16-bit char codes splits astral Unicode characters (such as emojis) into broken surrogate pairs (��). This HTML encoder iterates by complete Unicode code point using for...of and codePointAt(0):
Given this input containing markup, accents, and an emoji:
<div class="test">Café & Rocket 🚀</div>
In Special Only mode with Named entities, syntax delimiters are escaped:
<div class="test">Café & Rocket 🚀</div>
Switching to Decimal mode with Special + Non-ASCII enabled converts both the accented é and the rocket emoji cleanly into whole code points (in Named mode the é would become é instead):
<div class="test">Café & Rocket 🚀</div>
To turn entities back into text in bulk, use HTML Entity Decoder.