laurent
laurent

Reputation: 90776

Adding HTML elements that are not part of TinyMCE content

I wonder if there's a way with TinyMCE to add HTML elements, but without these elements being part of the content (i.e. if I call getContent() they will not appear).

My use case is to add for example a small toolbar to edit an element, and this toolbar should not appear in the code returned by getContent(). I couldn't find anything about it in the doc. Any idea if TinyMCE allows something like this?

Upvotes: 1

Views: 584

Answers (1)

Ben Long
Ben Long

Reputation: 383

You can configure which HTML elements will remain using the valid_elements, invalid_elements and extended_valid_elements options.

The valid_elements option defines which elements will remain in the edited text when the editor saves.

Example usage:

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  valid_elements : 'a[href|target=_blank],strong/b,div[align],br'
});

The invalid_elements option instructs the editor to remove specific elements when TinyMCE executes a cleanup.

Example usage:

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  invalid_elements : 'strong,em'
});

The extended_valid_elements option is very similar to valid_elements. The only difference between this option and valid_elements is that this one gets added to the existing rule set.

Example usage:

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  extended_valid_elements : 'img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]'
});

Check out the Tiny documentation for more information:

Upvotes: 1

Related Questions