Skip to content

Instantly share code, notes, and snippets.

@frozzare
Created January 19, 2013 18:55
Show Gist options
  • Save frozzare/4574306 to your computer and use it in GitHub Desktop.
Save frozzare/4574306 to your computer and use it in GitHub Desktop.
/**
* Escape given `html`
*
* @param {String} html
* @return {String} escaped html
*/
exports.escape = function (html) {
return String(html)
.replace(/&(?!\w+;)/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment