Problem/Motivation
When we add two adjacent tags using HTML source editing mode (General HTML Support (“GHS”) feature)
ckeditor5 merges those spans together.
Steps to reproduce
Try following code
<span> <span>aaaa</span> <span>bbbb</span> </span>
1. Copy above code and paste into editor with source mode.
2. Turn off source editing mode.
3. Turn ON source editing again and see above html changes.
There are couple of upstream issues for this:
- (marked as duplicate) https://github.com/ckeditor/ckeditor5/issues/15053
- (marked as duplicate) https://github.com/ckeditor/ckeditor5/issues/15046
- https://github.com/ckeditor/ckeditor5/issues/15408
Issue fork drupal-3389707
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
wim leersThat is quite the exotic use case!
What is the purpose of such markup?
Comment #3
jvogt commentedI wouldn't call it exotic for us. We're trying to write a ckeditor5 plugin that outputs a themed "button". The HTML structure is as follows:
ckeditor5 rewrites that to the following which doesn't work with the theme:
The theme CSS and HTML are provided by our institution and aren't Drupal-specific. We'd like to stick to the main theme as much as possible for the sake of maintenance and future compatibility, rather than reworking it to avoid nested spans. Also, from what I can tell, nesting a
<span>in another<span>is considered valid HTML so it seems reasonable for ckeditor to allow it.Comment #5
maddentim commentedI have a similar situation with a site now running Drupal 10.2.1 with ckeditor4 still. The blocker to going to ckeditor5 is that they have existing buttons like this:
the outer wrapper is just to make two buttons go side by side on desktop.
When this code is opened in ckeditor 5, it is transformed into:
This rearranging of the code breaks our button styling. I am open to changing our button CSS, but I don't see how I can make buttons with the current output. I tried turning off the "Correct faulty and chopped off HTML" to no avail.
Recently, I have been looking for a way to alter the input sent to the editor such that we could do some regex magic to find the buttons and rewrite the code so it works. My only solution that I see so far would be to set up a hook_form_alter function, look for the form_ids we need, then look for the fields and rewrite them. We have about 25 ckeditor fields so that could become a pretty hairy function. Open to suggestions.
Comment #6
wim leersRelated but different: #3393850: [upstream] CKEditor 5 moves <span> inside <a> tag.
Comment #8
wim leershttps://github.com/ckeditor/ckeditor5/issues/15408 is the new issue to track apparently 🤷♂️
Comment #9
maddentim commentedJust circling back here. We could not wait for a real fix from upstream so we opted to develop an alter hook that uses DOMDocument() to restructure the HTML prior to sending it into CK5. While our hook is very specific to our quirky button structure, maybe someone can use parts to fix their own issues!
Comment #10
wim leersThanks, @maddentim! I do hope it'll help somebody else in the short term :)
Comment #11
marianojp commentedNested span tag should be allowed. I'm also having this issue.
Comment #12
marianojp commentedHi All, I found a temporary solution. I created another text format - /admin/config/content/formats. I did not use ckeditor 5.
Comment #13
smustgrave commentedCan this one be closed?