1

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?

3
  • Wouldn't you write a plugin that sits in the toolbar of the editor itself? Commented Jun 9, 2020 at 9:02
  • For toolbar, I guess so, but it's more a general question. It's also how to provide alternate rendering for certain elements. For example a link to an audio file could be displayed as an audio player, but you wouldn't want the audio player to saved with the document. Not sure if I'm approaching this problem right actually. Commented Jun 9, 2020 at 11:19
  • I have an application where I need to be able to manipulate the content of Tiny in a variety of ways. I convert the html to JSON, which is easier to work with. Don't know if that helps. Commented Jun 9, 2020 at 11:24

1 Answer 1

1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.