Skip to main content

Content Filtering

These options control which HTML elements, attributes, and styles are allowed in editor content, how entities are encoded, and various security-related settings.

Schema and validation

OptionTypeDefaultDescription
schemastring'html5'HTML schema used to validate content.
verify_htmlbooleantrueValidate HTML against the schema on input and output.
valid_elementsstringRules defining which elements and attributes are valid. Replaces the default set entirely. Uses a compact rule syntax.
extended_valid_elementsstringAdditional valid element rules added on top of the defaults. Same syntax as valid_elements.
invalid_elementsstringComma-separated list of element names to strip from content.
valid_childrenstringRules for which elements are allowed as children of other elements.
custom_elementsstringComma-separated custom element names to add to the schema so they are not stripped.

Attributes and styles

OptionTypeDefaultDescription
valid_classesstring/objectRestrict which CSS classes are allowed. Pass a string for a global rule or an object keyed by element name.
valid_stylesstring/objectRestrict which inline styles are allowed. Same format as valid_classes.
invalid_stylesstring/objectInline styles to strip from content. Same format as valid_classes.

Cleanup and formatting

OptionTypeDefaultDescription
fix_list_elementsbooleanfalseAutomatically fix improperly nested list elements.
remove_trailing_brsbooleantrueRemove trailing <br> tags that browsers insert at the end of blocks.
pad_empty_with_brbooleanfalsePad empty block elements with <br> instead of &nbsp;.
preserve_cdatabooleanfalsePreserve CDATA sections in content instead of converting them to comments.
element_formatstring'html'Output format for void elements. 'html' produces <br>, 'xhtml' produces <br />.

Entity encoding

OptionTypeDefaultDescription
entity_encodingstring'named'How entities are encoded in the output. 'named' uses HTML entity names, 'numeric' uses numeric codes, 'raw' outputs raw characters.
entitiesstringCustom entity definition string, as semicolon-separated name/value pairs.
encodingstringOutput encoding. Set to 'xml' to produce XML-compatible output.

Content protection

OptionTypeDefaultDescription
protectRegExp[]Array of regular expressions matching content that should be protected from the parser and filtering.
convert_fonts_to_spansbooleantrueConvert deprecated <font> elements to <span> elements with inline styles. Deprecated option.
inline_stylesbooleantrueUse inline styles instead of HTML attributes for formatting. Deprecated option.

Security

OptionTypeDefaultDescription
xss_sanitizationbooleantrueEnable XSS sanitization of content.
allow_conditional_commentsbooleanfalseAllow HTML conditional comments in content.
allow_html_data_urlsbooleanfalseAllow data: URLs in HTML attributes.
allow_svg_data_urlsbooleanAllow data: URLs specifically for SVG content.
allow_unsafe_link_targetbooleanfalseAllow target="_blank" on links without automatically adding rel="noopener".
allow_script_urlsbooleanfalseAllow javascript: URLs in href and src attributes.
allow_html_in_named_anchorbooleanfalseAllow HTML content inside named anchor elements.
sandbox_iframesbooleantrueAdd a sandbox attribute to all <iframe> elements in content. Enabled by default in Editor42 as the fix for CVE-2024-29203 (upstream TinyMCE 6 defaults to false) — see Security.
convert_unsafe_embedsbooleantrueConvert potentially unsafe <object> and <embed> elements to safer alternatives. Enabled by default in Editor42 as the fix for CVE-2024-29881 (upstream TinyMCE 6 defaults to false) — see Security.

Example

editor42.init({
selector: 'textarea',
valid_elements: 'p,br,strong/b,em/i,a[href|target],ul,ol,li,h1,h2,h3',
invalid_elements: 'script,iframe',
entity_encoding: 'raw',
xss_sanitization: true,
allow_script_urls: false,
sandbox_iframes: true
});