tinymce.html
v4.5.2
Published
HTML parsing, filtering and serialization logic extracted from TinyMCE
Downloads
9
Maintainers
Readme
tinymce.html
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.
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">' +
'TinyMCE</a><p>Lorem <a>Ipsum</a></p>';
var root = parser.parse(initialHtml);
var result = serializer.serialize(root);
console.log(result);
// <p><strong class="foo">test</strong><a href="//tinymce.com">TinyMCE</a></p>
// <p>Lorem Ipsum</p>
Options
Schema:
valid_elements
valid_classes
valid_children
valid_styles
(usetinymce.html.Parser
for this option to work, nottinymce.html.DomParser
)extended_valid_elements
invalid_elements
custom_elements
schema
("html5"
,"html4"
,"html5-strict"
)
Parser:
Serializer:
indent
indent_before
indent_after