TinyMCE includes sophisticated logic for cleaning up
HTML content. What's interesting about this logic is that it's pure JavaScript.
It doesn't use any browser-specific APIs and can be used with Node.js.
Versions follow TinyMCE's, except 4.5.3: it's TinyMCE 4.5.2 plus a fix for
attribute values longer than ~500k characters (e.g. big data: images), which
were lost in Safari and other JavaScriptCore-based environments.
Example
var tinymce = require('tinymce.html');var schema = new tinymce.html.Schema({ valid_elements: "@[class],#p,span,a[!href],strong/b", valid_classes: "foo"});var parser = new tinymce.html.Parser({ forced_root_block: 'p'}, schema);var serializer = new tinymce.html.Serializer({ indent: true, indent_before: 'p', indent_after: 'p'}, schema);var html = '<B title="title" class="foo bar">test</B><a href="//tinymce.com">' +