Skip to content

Instantly share code, notes, and snippets.

@zheng1
Created November 26, 2013 08:31
Show Gist options
  • Save zheng1/7655106 to your computer and use it in GitHub Desktop.
Save zheng1/7655106 to your computer and use it in GitHub Desktop.
escapeHtml
var entityMap = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment