I’m implementing TinyMCE in a website and I’m having issues with pasting, I wondered if anyone has had this bug before.
The basic structure inside the textarea is like this:
<h5>I am a heading</h5>
<p>I am a paragraph</p>
So when I first start editing if I place the cursor at the beginning of the editor and hit return a couple of times, then go back to the top to paste something in above the h5, the paste wipes out the h5.
When I look in the format dropdown before I paste, it says I’m still in a heading 5 and in the status bar it says ‘Path: div » h3 » span.-span’, is there a common solution to this problem?
Thanks
Update – I’ve just noticed this happens when I insert a line break instead of pasting too.
Update 2 – It happens to the h5 if I have applied a colour to it within TinyMCE.
So I colour the heading, then put the cursor before it, press return and try to paste/line break in the new space above and that clears it out. When coloured the html of the h5 looks like this:
<h5>
<span style="color: #0000ff;">
I am a heading
</span>
</h5>
Ok, I revisited this problem and I figured it out.
It seems that through either something I did or through some bug from an action on TinyMCE (perhaps paste from Word?) a clearing div got wrapped around the content (or sometimes part of the content) and saved in the database that looked like this:
Whenever a paste or a linebreak insert was done inside this div it cleared the rest of the content, and removing the div fixed the issue.
I’m sorry I cannot uncover what caused this but I hope that at least helps anyone searching.
*Edit*
I think this may have to do with pasting from word and the allowed tags in tinyMCE.
Using tinyMCE as a more fully fledged web page editor I believe it is good practice to include the following line in the initialization options:
That will make tinyMCE allow any html tags you wish, and though I have yet to test it I believe this would also fix my pasting issue.