Param Singh
Param Singh

Reputation: 1366

Writing text before/after any html tag wraps it into html too

What is the current behavior?

When I do setContent initially on loading tinymce and set some html tag, say a div with a class "mydiv". On insering something by editing inside tinymce around that div causes the content to be either inserted inside that mydiv or creates another div with the same attributes and add the content in there

Steps to reproduce

SetContent some html into the editor Write something in the editor by pressing enter or go one line that div

What is the expected behavior?

It should not cause the newly entered text to be wrapped inside div or tags in its vicinity. I'm facing the problem since I have to implement email signature funcationality.

https://codepen.io/paramsinghvc/pen/XaVOzz?editors=1010

enter image description here

 tinymce.init({
 selector: '#textarea',
 plugins : 'advlist autolink link image lists charmap print preview',
 height: 300,
 init_instance_callback: function(e) {
   e.setContent('<div class="mydiv"><strong>Inital Text</strong></div>')
 }
});

Upvotes: 0

Views: 129

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13744

TinyMCE puts items in root blocks in order to make the content valid, well-formed HTML. There is a setting to change this behavior:

https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block

Please note the warning for that setting: "Note that not using p elements as a root block can severely cripple the functionality of the editor."

There are many bad things that can happen here as you are making it easier to make malformed HTML. The onus will now be on you to make sure that when you take this content and assemble it for use that your result is valid.

Upvotes: 1

Related Questions