There's an issue when linking a media item in the editor whereby it adds empty P tags.
It seems to happen when the editor renders, so switching back and forth between source view has the same effect. Or saving, then editing, then saving, then editing, etc.
You get this behavour:
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="e2ad1789-3001-430b-a4bb-18760a6ad1c1" href="/node/789">
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="7d46c2c3-9d96-403b-9519-ace26b847c1b"></drupal-media>
</a>
<p> </p>
<p> </p>
<p> </p>Right now I'm just using linkit, but the core link button would do the same thing. Unlinked Media items do not exhibit this behavior. What's the proper answer for someone wanting to use a media item within ckeditor and have it link somewhere specific if this isn't the way? It does work, it just has that undesirable side-effect at the moment.
| Comment | File | Size | Author |
|---|---|---|---|
| #58 | 3131055-contrib-ckeditor-58.patch | 1 KB | shawn dearmond |
| #55 | 3131055-core-ckeditor-55.patch | 1.21 KB | altcom_neil |
| #53 | 3131055-wrapped-drupal-image-empty-p.patch | 1.03 KB | dpi |
| #47 | 3131055-47.patch | 4.09 KB | _utsavsharma |
| #46 | interdiff_42_46.txt | 598 bytes | ameymudras |
Comments
Comment #4
ytsurkPossible duplicate #2876094: Linking an image creates an empty paragraph tag in CKEditor
Comment #5
aaronmchaleAgree with #4, #2876094: Linking an image creates an empty paragraph tag in CKEditor is further along, marking this as a duplicate.
Comment #6
someshver commentedComment #7
someshver commentedI am having same issue. Does anyone found solution for this?
Comment #8
someshver commentedI have found solution to this issue.
install ckeditor config module https://www.drupal.org/project/ckeditor_config and edit full HTML and add
"autoParagraph = false"
Comment #9
pameeela commentedThis is a duplicate of #2876094: Linking an image creates an empty paragraph tag in CKEditor, please use that issue for any further comments, to avoid duplication of effort.
Comment #10
robbm commentedNot sure #8 is the way forwards, since this is a deprecated setting.
http://origin-docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config-cf...
Comment #11
neclimdulSo after careful review I'm pretty confident the symptoms are the same as #2876094: Linking an image creates an empty paragraph tag in CKEditor but with a different plugin the has vastly different code so its not the same bug. Best I can tell at this point, its related to the dtd definition from here or maybe some hacks related to that. I'm not 100% clear where this is happening yet but if you null out the drupalmedia plugin and this doesn't happen and if you add drupal-media as supported in a paragraph you can start to get some different behaviors so something weird is going on there. Not 100% on the details yet though, there is a lot of code here without a lot of comments on how its interacting.
Comment #12
neclimdulAnother rambly post to dump what I found investigating this for the next person or latter incarnations of myself.
Turns out poking at the DTD does change the behavior a lot so I guess related but the real problem seems to be somewhere in the interaction between autoparagraphing and upcasting/downcasting. I got really lost trying to piece together how all of this is suppose to work with CKEditor plugins since there's a lot of callbacks and async operations and I'm just not familiar with their responsibilities, interfaces, and interactions. I'm going to have to figure out a way to work with a un-obfuscated version of ckeditor to trace this out and I had to step back from this for a bit.
Comment #13
finex commentedHi, I'm also experiencing this same problem: when I add a link to embedded media inside ckeditor, a
<p> </p>is added after the image.Comment #14
developerweeks commentedI know Google has this ticket ranked higher in its search results, that is how I got here. However, #5 and #9 are correct that this is a duplicate. If you (current reader) go to the other ticket, issue 2876094 with patch, you will see that it has a patch for this issue. As of the writing of this comment, that issue is in the "needs review" phase. I will be trying that patch shortly.
Comment #15
segovia94 commentedThis is a fundamentally different problem than #2876094: Linking an image creates an empty paragraph tag in CKEditor even though the symptom is the same (adding extra
<p>tags). I have tried the patch in that issue and it does not fix this problem.This issue occurs because the wrapping
<a>tag is an inline element which requires being wrapped inside of a block element like a<p>or<div>. A more detailed explanation can be found here https://www.drupal.org/project/entity_embed/issues/3070941#comment-13205975 where<drupal-entity>tags run into the same problem.Setting the
atag to a block element fixes this problem. Upcasting the link element may be a better solution, but as of now I couldn't get it working.Attached is a test to prove the problem.
Comment #16
segovia94 commentedThis should fix the problem, but I'm not sure it's the best solution since it turns
<a>tags into block elements. This may have unforeseen side effects. I've played around with it and haven't seen any yet, but it's something to be aware of.Comment #17
segovia94 commentedUnfortunately I don't think setting the
<a>tag as a block element is an acceptable solution. It ends up visually doing some weird stuff with spacing like when links are inside a paragraph of text. So a better solution will need to be implemented. In the mean time, here is a hacky patch that removes the extra paragraph. This patch is basically straight from #3070941: [upstream] Embed wrapped in an a tag + toggling source button creates extra p tags. At the very least it might help people that need a solution until a better one is made.Comment #18
segovia94 commentedComment #19
segovia94 commentedComment #20
segovia94 commentedQuick backport of the #17 patch for 8.9.x. Ignore this if you are on 9.x already.
Comment #22
stockticker commentedThank you so much for the patch, @segovia94. I can confirm that it works for my use case. And symptoms were exactly the same as attached in the video from a https://www.drupal.org/project/entity_embed/issues/3070941.
Also, I want to admit that current issue is not the same as in https://www.drupal.org/project/drupal/issues/2876094 (as mentioned by @segovia94 as well)
Comment #23
aaronmchaleThis is still "needs work" on account of review in #17.
Comment #25
annerl commentedMy problem is very similar: when embedding a node as teaser, the embedded entity gets surrounded by empty paragraphs. Like this:
I testet patch #17 in Drupal Core 9.2.7. But this didn't fix the problem.
Comment #26
aaronmchaleAfter a bit of testing, I was able to reproduce this issue using the current
ckeditorbut I was not able to reproduce this using the newckeditor5.CKEditor 5 will replace the current CKEditor 4 from Drupal 10.
Steps followed:
HEADusing umami demo profile.ckeditor5module, and updated basic and full html text formats to useckeditor5.So unless someone is very keen on getting this fixed before 10.0 is released, this will likely be closed as a won't fix.
For anyone who wants a quick fix, once you're able to, enable the new
ckeditor5core experimental module, and upgrade your text formats use it.Comment #27
saifullah.akber commentedI am also having the same issue. Every time I click on "source" from the toolbar it adds an extra p tags after the media image in CKeditor.
Anyone got this fixed?
Comment #28
wim leers#26: thank you very much for that testing! We indeed tried to make things work at least equally good in CKEditor 5 as they do in CKEditor 4, and I'm glad to see that this bug would not be carried over! :)
Comment #29
wim leersComment #30
sclsweb commentedI will go on record as being "very keen on getting this fixed before 10.0 is released."
I can't help with writing code but could test functionality on new patches. If someone has a different workaround for this issue I'd try that too, because the IMCE workaround is dreadful!
Comment #31
snable commentedI can confirm the excact same behaviour described in #27.
Switching back and forth to souece code view adds additional
tags - in my case whereever there already is a
already.
Comment #32
wrd-oaitsd commentedI ran into this problem (at least, I think it's this problem) today. We use the file_download_link module with a "Download link" view mode so that a media item can be embedded and appear as a download link. This works just fine in lists, but today someone tried embedding the file in the middle of a paragraph. A /p tag was inserted before the media item, and a p tag after it.
Switching to source code mode in the editor, deleting the tags, and saving produced the desired result, but switching back to wysiwyg mode brought the undesired tags back.
Comment #33
leisurman commented3131055-17.patch fixes this issue for me with Drupal 9.3.12
Comment #34
tzt20 commented3131055-17.patch also resolved the issue for me on 9.3.13
Comment #36
sclsweb commentedOthers' successes with the patch inspired me to retest -- and now on 9.3.13, 3131055-17.patch also resolved the issue for my sites.
Comment #37
graber commentedSolved an identical issue on entity_embed, but in a different way, one-liner actually, so maybe worth checking. Adding a related issue.
Comment #38
neerajsinghIt seems like, Drupal's link feature is not intended for embedded entities in CKEditor.
Meanwhile, it is worth, looking at the Entity Embed link module.
Comment #40
xaqroxThis commit moved all of media's ckeditor(4) stuff into the ckeditor(4) module, so patch from #17 doesn't apply anymore. Here's an updated patch, which applies successfully to 9.5.0-beta2.
Comment #41
quietone commentedComment #42
sandeepsingh199 commentedRe-rolled the #40 patch for D9.5.x-dev. Please check and review.
Comment #43
_pratik_Comment #44
_pratik_Patch with #42 CCF fix and interdiff between patches attached.
#42 Patch was not applying. Now Patch is applying cleanly for me.
Thanks
Comment #45
_pratik_Comment #46
ameymudras commentedFixing the coding standard issue with patch #42
Comment #47
_utsavsharma commentedFixed CCF of #46.
Please review.
Comment #48
gaurav-mathur commentedpatch #20 is wrong for 9.5.x , its need work
Comment #49
8bitplateau commentedPatch #47 applies to 9.5.3 successfully
Comment #50
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Want to take a step back and just take a look.
1. Has this been confirmed in ckeditor5?
2. If this is strictly a ckeditor4 issue what is the proposed solution, should be added to the issue summary.
Comment #51
aaronmchaleI confirmed in comment #26 that this issue is not relevant in CKEditor5 and so is only relevant to CKEditor4.
I suspect that measns this issue should be moved to the CKEditor4 contrib module, unless it will actually get fixed in 9.x (which seems unlikely at this point).
Comment #52
smustgrave commentedI doubt it. I’m not sure how ckeditor4 fixes are being handled. If we fix in 9.x it will have to be ported then
Comment #53
dpiConfirmed this issue with CKeditor 4, which I suppose is actually new contrib module.
I managed to adapt the solution also used in Entity Embed, as found at #3282295: Additional paragraphs added when embedding an entity in CKEditor and linking it, and suggested by @Graber above in #37.
The solution was as simple as adding the following lines to the Contrib ckeditor @
modules/contrib/ckeditor/js/plugins/drupalmedialibrary/plugin.jsafter the existingbeforeInitfunction:This solution is quite a lot simpler than the patch to date on this issue!
Attached patch for the ckeditor contrib
Comment #54
lunazoid commentedI will say that #53 seems to be working, but I haven't tested it extensively.
Comment #55
altcom_neil commentedI have tested the patch in #53 with Drupal 9.5.9 and it works, being as it is the same solution as provided for Entity Embeds drupal-entity tags it would seem to be the solution to go for.
Though we are still using the ckeditor bundled in the core not the contrib so I had to manually apply the changes to the core ckeditor module js.
Attached is the version of the patch for the core but using the same fix as #53.
Comment #56
davedg629 commentedI tested the patch in #53 and it prevents the accumulation of empty p tags, but it is now adding an empty p tag before each media embed that is wrapped in a link/a tag.
In other words, the code should look like this:
<p><a href="#">[drupal embed]</a></p>But it looks like this:
But like I said, this patch is an improvement as additional p tags aren't added every time you save the node like before.
Comment #57
segovia94 commentedSince Drupal 9 is End of Life today, I am moving this issue to the contrib module and re-rolling the patch from #55.
Comment #58
shawn dearmond commented#57 wasn't applying. Refactored it for the current 1.0.x branch.
Comment #59
segovia94 commentedAdded the original test back in.
Comment #60
segovia94 commentedmoved the test to the correct file