hexo-util
Version:
Utilities for Hexo.
25 lines • 797 B
JavaScript
const escapeTestNoEncode = /[<>"'`/=]|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
const escapeReplacements = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
'\'': ''',
'`': '`',
'/': '/',
'=': '='
};
const getEscapeReplacement = (ch) => escapeReplacements[ch];
function escapeHTML(str) {
if (typeof str !== 'string')
throw new TypeError('str must be a string!');
// https://github.com/markedjs/marked/blob/master/src/helpers.js
if (escapeTestNoEncode.test(str)) {
return str.replace(escapeReplaceNoEncode, getEscapeReplacement);
}
return str;
}
module.exports = escapeHTML;
//# sourceMappingURL=escape_html.js.map
;