21 lines
558 B
JavaScript
21 lines
558 B
JavaScript
Handlebars.registerHelper('escapeHTML', function(text, options) {
|
|
// See https://github.com/janl/mustache.js/blob/master/mustache.js#L60
|
|
var entityMap = {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": ''',
|
|
'/': '/',
|
|
'`': '`',
|
|
'=': '='
|
|
};
|
|
|
|
function escapeHtml (string) {
|
|
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
|
|
return entityMap[s];
|
|
});
|
|
}
|
|
return options.fn(escapeHtml(text));
|
|
});
|