Skip to content

Instantly share code, notes, and snippets.

@paulakreuger
Created March 26, 2014 09:20
Show Gist options
  • Save paulakreuger/9779508 to your computer and use it in GitHub Desktop.
Save paulakreuger/9779508 to your computer and use it in GitHub Desktop.
Escape Text
/*
==ESC
-----------------------------------------------------*/
function esc(text) {
if (typeof text !== 'string') {
text = String(text);
}
var html = text.split("&").join("&amp;").split("\"").join("&quot;").split("'").join("&#39;").split("<").join("&lt;").split(">").join("&gt;");
return html.replace(/\r?\n/g, '&#10;');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment