Files
blog/node_modules/hexo-util/dist/escape_html.js
2025-07-16 16:30:56 +00:00

25 lines
797 B
JavaScript

"use strict";
const escapeTestNoEncode = /[<>"'`/=]|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
const escapeReplacements = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#39;',
'`': '&#96;',
'/': '&#x2F;',
'=': '&#x3D;'
};
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