Skip to content
Create a gist now

Instantly share code, notes, and snippets.

more efficient catch-all
var MAP = { '&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'};
function escapeHTML (s, forAttribute) {
return s.replace(forAttribute ? /[&<>'"]/g : /[&<>]/g, function(c) {
return MAP[c];
});
}
@Chexpir

This approach does not work for something such as
escapeHTML("English")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.