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
schemastringhtml5HTML schema used to validate content.
verify_htmlbooleantrueValidate HTML against the schema on input and output.
valid_elementsstring—Rules defining which elements and attributes are valid. Replaces the default set entirely. Uses a compact rule syntax.
extended_valid_elementsstring—Additional valid element rules added on top of the defaults. Same syntax as valid_elements.
invalid_elementsstring—Comma-separated list of element names to strip from content.
valid_childrenstring—Rules for which elements are allowed as children of other elements.
custom_elementsstring—Comma-separated custom element names to add to the schema so they are not stripped.

Attributes and styles​

OptionTypeDefaultDescription
valid_classesstring/object—Restrict which CSS classes are allowed. Pass a string for a global rule or an object keyed by element name.
valid_stylesstring/object—Restrict which inline styles are allowed. Same format as valid_classes.
invalid_stylesstring/object—Inline 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_formatstringhtmlOutput format for void elements. html produces <br>, xhtml produces <br />.

Entity encoding​

OptionTypeDefaultDescription
entity_encodingstringnamedHow entities are encoded in the output. named uses HTML entity names, numeric uses numeric codes, raw outputs raw characters.
entitiesstring—Custom entity definition string, as semicolon-separated name/value pairs.
encodingstring—Output 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_urlsboolean—Allow 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 an empty sandbox attribute to every <iframe> in content whose host is not in sandbox_iframes_exclusions. Enabled by default in Editor42 as the fix for CVE-2024-29203 (upstream TinyMCE 6 defaults to false) — see Security.
sandbox_iframes_exclusionsstring[]10 video, music and code hostsHosts whose iframes get no sandbox, subdomains included (google.com covers www.google.com). The default list is youtube.com, youtu.be, vimeo.com, player.vimeo.com, dailymotion.com, dai.ly, codepen.io, embed.music.apple.com, open.spotify.com and giphy.com. A list you set replaces it, so name the default hosts you need again.
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
});