HTML Output Formatting

What the editor savesis configurable independently of what the author sees. That matters when the HTML is going somewhere with rules of its own — a CMS field, an email template, a feed — and you would rather constrain it at the source than sanitise it downstream forever.

Filters unwrap; they do not delete. A tag that fails the filter is removed but its text is kept, so a whitelist is a way to flatten markup, not a way to discard content. If you need content gone, that is a different job.

enterKeyTag: "div"

Press Enter inside this editor — new blocks are <div> rather than <p>.

Saved HTML

Loading…

tagWhiteList: ["p", "strong"]

Only <p> and <strong> survive. The heading, emphasis, colour span and table are unwrapped — their text remains.

Saved HTML

Loading…

tagBlackList: ["strong", "table", "tr", "td", "tbody"]

The inverse: these are unwrapped and everything else is left alone.

Saved HTML

Loading…

htmlcode_forcehexformat: true

Colours are written as #rrggbb instead of rgb(r,g,b).

Saved HTML

Loading…

Example code

// Which element a new block gets. Default "p".
new RichTextEditor("#editor", { enterKeyTag: "div" });

// Shift+Enter. Default is a <br>; set it to make Shift+Enter a block too.
new RichTextEditor("#editor", { shiftEnterKeyTag: "p" });

// Keep ONLY these elements. Anything else is unwrapped — its text survives.
new RichTextEditor("#editor", { tagWhiteList: ["p", "strong"] });

// Or unwrap just these, keeping everything else.
new RichTextEditor("#editor", { tagBlackList: ["strong", "table", "tr", "td", "tbody"] });

// Emit colours as #rrggbb rather than rgb(r,g,b).
new RichTextEditor("#editor", { htmlcode_forcehexformat: true });

tagWhiteList takes precedence: if it is set and non-empty, tagBlackList is not consulted at all. Both expect lower-case tag names.

For removing dangerous markup rather than shaping tidy markup, see the paste cleaner— a filter list is a formatting tool, not a security boundary.

Configuration reference