Skip to content

Instantly share code, notes, and snippets.

@pyrocat101
Created May 17, 2013 03:46
Show Gist options
  • Save pyrocat101/5596796 to your computer and use it in GitHub Desktop.
Save pyrocat101/5596796 to your computer and use it in GitHub Desktop.
Escape the given string of `html`
/**
* Escape the given string of `html`.
*
* @param {String} html
* @return {String}
* @api private
*/
exports.escape = function escape(html){
return String(html)
.replace(/&(?!(\w+|\#\d+);)/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
@pyrocat101
Copy link
Author

Extracted from jade's runtime.js.

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