function text_to_html(t){
function fixedCharCodeAt(str) {
var code = str.charCodeAt(0);
var hi, low;
if (0xD800 <= code && code <= 0xDBFF) {
hi = code;
low = str.charCodeAt(1);
if (isNaN(low))throw 'Старшая часть суррогатной пары без следующей младшей в fixedCharCodeAt()';
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
}
if (0xDC00 <= code && code <= 0xDFFF)return false;
return code;
}
function encode_html_entities(string){
return string?""+Array.from(string).map(function(a){return fixedCharCodeAt(a);}).join(";")+";":"";
}
}
Демо:
Результат: ¯\_(ツ)_/¯
И не забудь поделиться (: