Last active
May 25, 2016 12:51
-
-
Save englishextra/214582c0f3ba64be19c655f57f11241d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* escape string for HTML attributes and titles | |
* gist.github.com/englishextra/214582c0f3ba64be19c655f57f11241d | |
*/ | |
function escapeHtml(s) { | |
return s = s.replace(/[<!="'\/>&]/g, function (s) { | |
return { | |
"<" : "<", | |
"!" : "!", | |
"=" : "=", | |
'"' : """, | |
"'" : "'", | |
"/" : "/", | |
">" : ">", | |
"&" : "&" | |
} | |
[s] | |
}) || ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment