You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
48 KiB
148 lines
48 KiB
4 years ago
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var ENTITIES = [['Aacute', [193]], ['aacute', [225]], ['Abreve', [258]], ['abreve', [259]], ['ac', [8766]], ['acd', [8767]], ['acE', [8766, 819]], ['Acirc', [194]], ['acirc', [226]], ['acute', [180]], ['Acy', [1040]], ['acy', [1072]], ['AElig', [198]], ['aelig', [230]], ['af', [8289]], ['Afr', [120068]], ['afr', [120094]], ['Agrave', [192]], ['agrave', [224]], ['alefsym', [8501]], ['aleph', [8501]], ['Alpha', [913]], ['alpha', [945]], ['Amacr', [256]], ['amacr', [257]], ['amalg', [10815]], ['amp', [38]], ['AMP', [38]], ['andand', [10837]], ['And', [10835]], ['and', [8743]], ['andd', [10844]], ['andslope', [10840]], ['andv', [10842]], ['ang', [8736]], ['ange', [10660]], ['angle', [8736]], ['angmsdaa', [10664]], ['angmsdab', [10665]], ['angmsdac', [10666]], ['angmsdad', [10667]], ['angmsdae', [10668]], ['angmsdaf', [10669]], ['angmsdag', [10670]], ['angmsdah', [10671]], ['angmsd', [8737]], ['angrt', [8735]], ['angrtvb', [8894]], ['angrtvbd', [10653]], ['angsph', [8738]], ['angst', [197]], ['angzarr', [9084]], ['Aogon', [260]], ['aogon', [261]], ['Aopf', [120120]], ['aopf', [120146]], ['apacir', [10863]], ['ap', [8776]], ['apE', [10864]], ['ape', [8778]], ['apid', [8779]], ['apos', [39]], ['ApplyFunction', [8289]], ['approx', [8776]], ['approxeq', [8778]], ['Aring', [197]], ['aring', [229]], ['Ascr', [119964]], ['ascr', [119990]], ['Assign', [8788]], ['ast', [42]], ['asymp', [8776]], ['asympeq', [8781]], ['Atilde', [195]], ['atilde', [227]], ['Auml', [196]], ['auml', [228]], ['awconint', [8755]], ['awint', [10769]], ['backcong', [8780]], ['backepsilon', [1014]], ['backprime', [8245]], ['backsim', [8765]], ['backsimeq', [8909]], ['Backslash', [8726]], ['Barv', [10983]], ['barvee', [8893]], ['barwed', [8965]], ['Barwed', [8966]], ['barwedge', [8965]], ['bbrk', [9141]], ['bbrktbrk', [9142]], ['bcong', [8780]], ['Bcy', [1041]], ['bcy', [1073]], ['bdquo', [8222]], ['becaus', [8757]], ['because', [8757]], ['Because', [8757]], ['bemptyv', [10672]], ['bepsi', [1014]], ['bernou', [8492]], ['Bernoullis', [8492]], ['Beta', [914]], ['beta', [946]], ['beth', [8502]], ['between', [8812]], ['Bfr', [120069]], ['bfr', [120095]], ['bigcap', [8898]], ['bigcirc', [9711]], ['bigcup', [8899]], ['bigodot', [10752]], ['bigoplus', [10753]], ['bigotimes', [10754]], ['bigsqcup', [10758]], ['bigstar', [9733]], ['bigtriangledown', [9661]], ['bigtriangleup', [9651]], ['biguplus', [10756]], ['bigvee', [8897]], ['bigwedge', [8896]], ['bkarow', [10509]], ['blacklozenge', [10731]], ['blacksquare', [9642]], ['blacktriangle', [9652]], ['blacktriangledown', [9662]], ['blacktriangleleft', [9666]], ['blacktriangleright', [9656]], ['blank', [9251]], ['blk12', [9618]], ['blk14', [9617]], ['blk34', [9619]], ['block', [9608]], ['bne', [61, 8421]], ['bnequiv', [8801, 8421]], ['bNot', [10989]], ['bnot', [8976]], ['Bopf', [120121]], ['bopf', [120147]], ['bot', [8869]], ['bottom', [8869]], ['bowtie', [8904]], ['boxbox', [10697]], ['boxdl', [9488]], ['boxdL', [9557]], ['boxDl', [9558]], ['boxDL', [9559]], ['boxdr', [9484]], ['boxdR', [9554]], ['boxDr', [9555]], ['boxDR', [9556]], ['boxh', [9472]], ['boxH', [9552]], ['boxhd', [9516]], ['boxHd', [9572]], ['boxhD', [9573]], ['boxHD', [9574]], ['boxhu', [9524]], ['boxHu', [9575]], ['boxhU', [9576]], ['boxHU', [9577]], ['boxminus', [8863]], ['boxplus', [8862]], ['boxtimes', [8864]], ['boxul', [9496]], ['boxuL', [9563]], ['boxUl', [9564]], ['boxUL', [9565]], ['boxur', [9492]], ['boxuR', [9560]], ['boxUr', [9561]], ['boxUR', [9562]], ['boxv', [9474]], ['boxV', [9553]], ['boxvh', [9532]], ['boxvH', [9578]], ['boxVh', [9579]], ['boxVH', [9580]], ['boxvl', [9508]], ['boxvL', [9569]], ['boxVl', [9570]], ['boxVL', [9571]], ['boxvr', [9500]], ['boxvR', [9566]], ['boxVr', [9567]], ['boxVR', [9568]], ['bprime', [8245]], ['breve', [728]], ['Breve', [728]], ['brvbar', [166]], ['bscr', [119991]], ['Bscr', [8492]], ['bsemi', [8271]], ['bsim', [8765]], ['bsime', [8909]], ['bsolb', [10693]], ['bsol', [92]], ['bsolhsub', [10184]], ['bull', [8226]], ['bullet', [8226]], ['bump', [8782]], ['bumpE', [10926]], ['bumpe', [8783]], ['Bumpeq', [8782]
|
||
|
var alphaIndex = {};
|
||
|
var charIndex = {};
|
||
|
createIndexes(alphaIndex, charIndex);
|
||
|
var Html5Entities = /** @class */ (function () {
|
||
|
function Html5Entities() {
|
||
|
}
|
||
|
Html5Entities.prototype.decode = function (str) {
|
||
|
if (!str || !str.length) {
|
||
|
return '';
|
||
|
}
|
||
|
return str.replace(/&(#?[\w\d]+);?/g, function (s, entity) {
|
||
|
var chr;
|
||
|
if (entity.charAt(0) === "#") {
|
||
|
var code = entity.charAt(1) === 'x' ?
|
||
|
parseInt(entity.substr(2).toLowerCase(), 16) :
|
||
|
parseInt(entity.substr(1));
|
||
|
if (!(isNaN(code) || code < -32768 || code > 65535)) {
|
||
|
chr = String.fromCharCode(code);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
chr = alphaIndex[entity];
|
||
|
}
|
||
|
return chr || s;
|
||
|
});
|
||
|
};
|
||
|
Html5Entities.decode = function (str) {
|
||
|
return new Html5Entities().decode(str);
|
||
|
};
|
||
|
Html5Entities.prototype.encode = function (str) {
|
||
|
if (!str || !str.length) {
|
||
|
return '';
|
||
|
}
|
||
|
var strLength = str.length;
|
||
|
var result = '';
|
||
|
var i = 0;
|
||
|
while (i < strLength) {
|
||
|
var charInfo = charIndex[str.charCodeAt(i)];
|
||
|
if (charInfo) {
|
||
|
var alpha = charInfo[str.charCodeAt(i + 1)];
|
||
|
if (alpha) {
|
||
|
i++;
|
||
|
}
|
||
|
else {
|
||
|
alpha = charInfo[''];
|
||
|
}
|
||
|
if (alpha) {
|
||
|
result += "&" + alpha + ";";
|
||
|
i++;
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
result += str.charAt(i);
|
||
|
i++;
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
Html5Entities.encode = function (str) {
|
||
|
return new Html5Entities().encode(str);
|
||
|
};
|
||
|
Html5Entities.prototype.encodeNonUTF = function (str) {
|
||
|
if (!str || !str.length) {
|
||
|
return '';
|
||
|
}
|
||
|
var strLength = str.length;
|
||
|
var result = '';
|
||
|
var i = 0;
|
||
|
while (i < strLength) {
|
||
|
var c = str.charCodeAt(i);
|
||
|
var charInfo = charIndex[c];
|
||
|
if (charInfo) {
|
||
|
var alpha = charInfo[str.charCodeAt(i + 1)];
|
||
|
if (alpha) {
|
||
|
i++;
|
||
|
}
|
||
|
else {
|
||
|
alpha = charInfo[''];
|
||
|
}
|
||
|
if (alpha) {
|
||
|
result += "&" + alpha + ";";
|
||
|
i++;
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
if (c < 32 || c > 126) {
|
||
|
result += '&#' + c + ';';
|
||
|
}
|
||
|
else {
|
||
|
result += str.charAt(i);
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
Html5Entities.encodeNonUTF = function (str) {
|
||
|
return new Html5Entities().encodeNonUTF(str);
|
||
|
};
|
||
|
Html5Entities.prototype.encodeNonASCII = function (str) {
|
||
|
if (!str || !str.length) {
|
||
|
return '';
|
||
|
}
|
||
|
var strLength = str.length;
|
||
|
var result = '';
|
||
|
var i = 0;
|
||
|
while (i < strLength) {
|
||
|
var c = str.charCodeAt(i);
|
||
|
if (c <= 255) {
|
||
|
result += str[i++];
|
||
|
continue;
|
||
|
}
|
||
|
result += '&#' + c + ';';
|
||
|
i++;
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
Html5Entities.encodeNonASCII = function (str) {
|
||
|
return new Html5Entities().encodeNonASCII(str);
|
||
|
};
|
||
|
return Html5Entities;
|
||
|
}());
|
||
|
exports.Html5Entities = Html5Entities;
|
||
|
function createIndexes(alphaIndex, charIndex) {
|
||
|
var i = ENTITIES.length;
|
||
|
while (i--) {
|
||
|
var e = ENTITIES[i];
|
||
|
var alpha = e[0];
|
||
|
var chars = e[1];
|
||
|
var chr = chars[0];
|
||
|
var addChar = (chr < 32 || chr > 126) || chr === 62 || chr === 60 || chr === 38 || chr === 34 || chr === 39;
|
||
|
var charInfo = void 0;
|
||
|
if (addChar) {
|
||
|
charInfo = charIndex[chr] = charIndex[chr] || {};
|
||
|
}
|
||
|
if (chars[1]) {
|
||
|
var chr2 = chars[1];
|
||
|
alphaIndex[alpha] = String.fromCharCode(chr) + String.fromCharCode(chr2);
|
||
|
addChar && (charInfo[chr2] = alpha);
|
||
|
}
|
||
|
else {
|
||
|
alphaIndex[alpha] = String.fromCharCode(chr);
|
||
|
addChar && (charInfo[''] = alpha);
|
||
|
}
|
||
|
}
|
||
|
}
|