$ npm install browser-sanitize-htmlSanitize html, for browser environments.
Allow only divs and clear style attributes:
var sanitize = require('browser-sanitize-html');
var domify = require('domify');
var dirty = domify('<div><span></span><div style="foo:bar"></div></div>');
var clean = sanitize(dirty, function(el) {
if (el.tagName != 'DIV') return false;
el.setAttribute('style', null);
});
console.log(clean);
// => <div><div></div><div>
Install with npm
npm install browser-sanitize-html
and bundle with browserify.
Sanitize dirty dom through your provided filter function. The return
value will be null, one Element or a Fragment, depending on which
Elements matched.
When filter returns false for an element it will be removed from the result
set. You can also modify nodes you want to keep on the fly.
MIT.