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
Before

After
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

  1. Go to a text format config page (/admin/config/content/formats/manage/full_html)
  2. Chose the CKEditor 4 as the text editor.
  3. Remove the style plugin from the active toolbar.
  4. Tick the 'Limit allowed HTML tags and correct faulty HTML' filter and add the following into the 'Allowed HTML tags'
    <a class>
  5. Change the text editor to CKEditor 5
  6. 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 log

  7. The a tag in the 'Allowed HTML tags' now is changed to <a href> and this setting is read-only in CKEditor 5.
  8. 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.

Comments

Mingsong created an issue. See original summary.

mingsong’s picture

StatusFileSize
new49.88 KB
new12.14 KB
new9.59 KB
mingsong’s picture

Issue summary: View changes
mingsong’s picture

Issue summary: View changes
mingsong’s picture

Issue summary: View changes
mingsong’s picture

After 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.

mingsong’s picture

Version: 10.1.x-dev » 11.x-dev
mingsong’s picture

Issue summary: View changes
mingsong’s picture

Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.