Problem/Motivation
During the auto-migrate process from CKEditor 4 to 5, if the Style plugin was not enabled previously in the CKEditor4, the class attribute for html tag that supported by a plugin, such as the A tag, will be removed from the allowed list in the 'Limit allowed HTML tags and correct faulty HTML' filter.
The consequence is that those contents were created in CKEditor 4, in which there is a link tag with class attribute will lose the styling as the 'class' attribute is filtered out after migrating to CKEditor 5.
Before migrated to CKEditor 5

After

The class attribute of the link is filtered out.
This bug only occur with the following conditions:
- Migrate from CKEditor 4 to 5.
- The Style plugin was not enabled prior to migration.
- The class attribute is belong to a html tag that is supported by a CKEditor 5 plugin. For example
<a>tag supported by the Link plugin.
Steps to reproduce
- Go to a text format config page (/admin/config/content/formats/manage/full_html)
- Chose the CKEditor 4 as the text editor.
- Remove the style plugin from the active toolbar.
- Tick the 'Limit allowed HTML tags and correct faulty HTML' filter and add the following into the 'Allowed HTML tags'
<a class> - Change the text editor to CKEditor 5
- At this point, there is a Drupal log said
'The CKEditor 5 migration process enabled the following plugins to support specific attributes that are allowed by the Rich text text format: Style ( for tag:
<a>to support: cla.'The typo in the log message is another problem.

- The a tag in the 'Allowed HTML tags' now is changed to
<a href> and this setting is read-only in CKEditor 5. - The style plugin is auto-enabled during the migrate process.But no allowed class attribute.
Proposed resolution
Leave the class attribute as it was in the 'Allowed HTML tags' setting after migrating to CKEditor 5 from 4.
Remaining tasks
A merge request to fix this bug.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
Fix a bug which cause an allowed tag's class attribute is filtered out unexpectedly after migrating from CKEditor 4 to 5.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | After migrated to CKEditor 5.png | 9.59 KB | mingsong |
| #2 | Before migrated to CKEditor 5.png | 12.14 KB | mingsong |
| #2 | The log.png | 49.88 KB | mingsong |
Comments
Comment #2
mingsongComment #3
mingsongComment #4
mingsongComment #5
mingsongComment #6
mingsongAfter debugging the code, I got my head around this issue.
Basically, when migrating from CKEditor 4 to 5, the Drupal\ckeditor5\SmartDefaultSettings::computeSmartDefaultSettings() will work out what CKEditor5 plugins need to enable according to the allowed html tags settings in CKEditor4.
Since the ckeditor5_style plugin provides the configuration for the class attribute on any tags, the Style plugin will be enabled if there is a class attribute of any tags specified in the 'Allow HTML tags' settings. Meanwhile, the class attribute will be removed from the 'Allow HTML tags' settings.
The problem with this approach is that the Style plugin won't provide a default settings that apply to all classes, instead, you have to specify one or more class name explicitly. See the line 76 in /ckeditor5/src/Plugin/CKEditor5Plugin/Style.php
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/ckedi...
In other words, you can not use a wildcard for the class name.
Also the Source Editing Plugin (ckeditor5_sourceEditing) won't add the class attribute into the 'Manually editable HTML tags' neither, since another plugin (Style plugin) is supposed to support that.
This issue affects Drupal 10.1, 10.2 and 11.
Comment #7
mingsongComment #8
mingsongComment #9
mingsong