When using the mediaEmbed plugin, the fake elements that get dropped on the page are img elements. This allows them to be contained by a p, or rather forces them to be contained by a p.

while editing:

<p> <img fake element /> </p>

Then, when the magic happens and the img is replaced by a div holding the iframe or the object or whatever, that p tag remains wrapped around what used to be an img, but is now a div. This is invalid HTML, and causes ugly styling errors.

viewing:

<p><div class='media-embed'><stuff /></div></p>

To make matters worse, the split p tags then close when you go to re-edit the content, so now you've got

<p>&nbsp;</p>
<p><img fake element</p>
<p>&nbsp;</p>

and there should't be any p tags!

help!

thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkesicki’s picture

Priority: Major » Normal
tmsimont’s picture

sorry for getting carried away with priority, but i figured that production of invalid html that results in an additional pair of empty p tags on each page edit was kind of major.

hdcoder’s picture

there was a solution?

tmsimont’s picture

not that i'm aware of.. i had to throw together a filter that ran a regex on the input and removed any <p> tags that were wrapped around a div

generalredneck’s picture

Version: 6.x-1.6 » 7.x-1.18
Issue summary: View changes

Still an issue 6 years later.

This causes difficulty editing content as when you do something like edit a node with markup like
<p><div class='media-embed'><stuff /></div></p>
or you hit the "Switch to plain text editor" and back, you get some extra empty paragraphs from the formatting being fixed. It turns into
<p>&nbsp;</p><divclass='media-embed'><stuff /></div><p>&nbsp;</p>
which is no bueno.

generalredneck’s picture

Version: 7.x-1.18 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
851 bytes

Ok I think I've got a fix for this. It only goes one level deep and works only for paragraph tags... so if you have something else wrapping it... this doesn't work in that usecase (and that can happen if you are in the middle of a link or something... But mejor que nada?

generalredneck’s picture

A quick fix. Turns out my previous logic failed when the embedded element happened when there was no establish dom... example as the very first thing you did.