Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created September 14, 2010 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save padolsey/579493 to your computer and use it in GitHub Desktop.
Save padolsey/579493 to your computer and use it in GitHub Desktop.
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
@jdalton
Copy link

jdalton commented Sep 14, 2010

Doesn't handle quotes but can handle many more entities...
http://github.com/jdalton/fusejs/blob/master/src/lang/html.js#L51-131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment