Problem/Motivation

<drupal-media> elements are removed by CKEditor 5 if embed media is disabled even when using Full HTML configuration. With CKEditor 4 the same configuration would retain <drupal-media> elements.

The same is true for any custom/non-official HTML tag. Only those that have a CKEditor 5 plugin to add support for them can be retained (such as <drupal-media>), but any/all custom/non-official HTML tags must be retained when a text format+CKEditor 5 are configured to allow arbitrary HTML.

Steps to reproduce

  1. Create one text format which has media embed and media library enabled
  2. Create Full HTML text formats for CKEditor 5 and CKEditor 4 and ensure media embed filter is disabled
  3. Create content that includes <drupal-media> using text format that has media embed enabled
  4. Switch to CKEditor 4 Full HTML and ensure that <drupal-media> is retained
  5. Switch to CKEditor 5 Full HTML and ensure that <drupal-media> is removed

Proposed resolution

Wait for upstream bugfix: https://github.com/ckeditor/ckeditor5/issues/11432

Remaining tasks

TBD

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

TBD

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

xjm’s picture

Priority: Major » Critical
Issue tags: +Drupal 10
Parent issue: » #3238333: Roadmap to CKEditor 5 stable in Drupal 9
Wim Leers’s picture

Title: Full HTML <drupal-media> elements are removed if embed media is disabled » [upstream] Full HTML <drupal-media> elements are removed if embed media is disabled
Issue tags: +data loss, +Needs upstream bugfix

Wow, this is bad.

Added to #3238333: Roadmap to CKEditor 5 stable in Drupal 9.

So it would seem that

…
    config:
      htmlSupport:
        allow:
          -
            name:
              regexp:
                pattern: /.*/
            attributes: true
            classes: true
            styles: true

configures GHS to support every HTML element … as long as CKEditor 5 knows about it.

IOW: custom elements are stripped?! 🙈😱

Sadly, yes, reproduced with simply this:

<p>p</p>
<yo>yo</yo>

gets converted to

<p>p</p>
<p>yo</p>

by CKE5. In CKE4, this was kept unchanged.

This feels/sounds similar to #3245950: [upstream] <script> tag support in GHS and #3256566: [upstream] <style> tag support in GHS, which were trivial fixes upstream for them, both using the same approach. Let's hope the same approach works for arbitrary unknown elements 🤞

This is impossible to solve on the Drupal side because Drupal does not and cannot know which HTML elements are being used in a particular piece of rich text. And even if we analyzed a stored piece of rich text, then we still wouldn't be able to predict which additional custom elements would be entered (or pasted) by the user in the future.

Will raise this in Thursday's call with the CKEditor 5 team. Sending them this right away, because this is of the highest possible priority.

Wim Leers’s picture

Issue summary: View changes
Wim Leers’s picture

Status: Active » Postponed

Confirmed with @lauriii.

Wim Leers’s picture

⚠️ Was informed by the CKEditor 5 team that this will not be fixed in the April 6 release (https://github.com/ckeditor/ckeditor5/issues/11387), but in the release after that (May).

Wim Leers’s picture

Title: [upstream] Full HTML <drupal-media> elements are removed if embed media is disabled » [upstream] [drupalMedia] Full HTML <drupal-media> elements are removed if embed media is disabled

Wim Leers credited dom.

Wim Leers’s picture

Title: [upstream] [drupalMedia] Full HTML <drupal-media> elements are removed if embed media is disabled » [upstream] [GHS] Custom/unofficial HTML tags not retained: <drupal-media>, <drupal-entity>, <foobar>
Issue summary: View changes

The issue title makes it sound like this is a bug specific to <drupal-media>, but that's not the case. Improved the title + issue summary to clarify the impact scope.

Thanks @dom for confirming this problem with <drupal-entity>, for which a filter exists (https://www.drupal.org/project/entity_embed), but no CKEditor 5 plugin exists yet, and so no work-around is possible … and simply starting to use CKEditor 5 on a "Full HTML-like" text format that uses the Entity Embed filter will today simply lose all the embedded entities upon editing!

Dom.’s picture

In the case of my website, this issue completely prevent any adoption of any Drupal version where CKE5 is the norm.
For that reason, I added Entity Embed in the list of "needs Drupal 10 & CKE5 readiness" tracked at : https://www.drupal.org/node/3273985

Note that because the tag is completely stripped, if a user edits a node with any custom element, the data are lost as the node is saved. If you don't have revisions activated, those data are lost forever.

I would be interested to build an MVP workaround for those modules that users or even the module maintainers could use in the meantime of a proper implementation. That MVP should just register the tag and all it's possible attributes to CKEditor 5 so they are not stripped. Eventually, it could replace it in CKE view (not in save) by a red square marked "no preview available" for instance. If you have instructions, documentation or direction to point for helping on that, it would be great.

Wim Leers’s picture

In the case of my website, this issue completely prevent any adoption of any Drupal version where CKE5 is the norm.

We know, that's why this is a critical data loss bug — the CKEditor team knows this is hard blocker for the CKEditor 5 module from becoming stable.

Thanks for confirming this though, having confirmation from concrete sites also helps convey this to them :) 👍

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wim Leers’s picture

Per @lauriii: https://github.com/ckeditor/ckeditor5/pull/11744 was merged which should address this stable blocker! 🥳

fago’s picture

unfortunately the latest ckeditor release does not include the change yet

xjm’s picture

Issue tags: +Drupal 10 beta blocker
catch’s picture

Status: Postponed » Active
Issue tags: -Needs upstream bugfix

This was released in ckeditor 34.2.0. Not sure what specifically needs to happen in this issue.

catch’s picture

Title: [upstream] [GHS] Custom/unofficial HTML tags not retained: <drupal-media>, <drupal-entity>, <foobar> » [GHS] Custom/unofficial HTML tags not retained: <drupal-media>, <drupal-entity>, <foobar>

No longer blocked on upstream.

Wim Leers’s picture

lauriii’s picture

Status: Active » Needs review
FileSize
2.16 KB
Wim Leers’s picture

Status: Needs review » Needs work

Manual testing

I wrote this in #3:

Sadly, yes, reproduced with simply this:

<p>p</p>
<yo>yo</yo>

gets converted to

<p>p</p>
<p>yo</p>

by CKE5. In CKE4, this was kept unchanged.

But today (thanks to #3301495: Update CKEditor 5 to 35.0.1), it gets converted to:

<p>
    p
</p>
<yo>yo</yo>

So … the bug has indeed been fixed upstream! 🥳

Tests

All that remains is test coverage.

@lauriii wrote that in #19.

+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php
@@ -495,7 +495,7 @@ public function testFullHtml() {
+    $assert_session->responseContains('<foo></foo><p><a foo="bar" hreflang="en" href="https://example.com"><abbr title="National Aeronautics and Space Administration">NASA</abbr> is an acronym.</a></p>');

I'd like this to be expanded slightly: I'd like both

  • <foo></foo>, which this already
    has
  • <bar>bar</bar>, to test the expected behavior for text contents of custom/unofficial tags when switching to a text format that does not allow this custom tag(I expect it to be converted to <p>bar</p>)

Once that's addressed, this is RTBC!

lauriii’s picture

Status: Needs work » Needs review
FileSize
2.21 KB
1.79 KB

Good idea! I did that and added an arbitrary attribute too.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Better still! 👏

catch’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php
    @@ -529,7 +529,7 @@ public function testFullHtml() {
         $assert_session->responseContains('<p><a href="https://example.com" hreflang="en">NASA is an acronym.</a></p>');
    

    It' very possible I'm missing something, but shouldn't this assertion also check that contents of the foo tag is still there? i.e.:

    ⬅️✌️➡️

lauriii’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.35 KB
836 bytes

Good catch! I think that would be a great addition to the test even though it has more to do with testing CKEditor 5 internals than testing our integration.

Moving back to RTBC since it's a very small change so a committer review on this should be sufficient.

  • catch committed cc2cafc on 10.1.x
    Issue #3268306 by lauriii, Wim Leers, catch, Dom.: [GHS] Custom/...

  • catch committed 3f16a42 on 10.0.x
    Issue #3268306 by lauriii, Wim Leers, catch, Dom.: [GHS] Custom/...
  • catch committed a868784 on 9.5.x
    Issue #3268306 by lauriii, Wim Leers, catch, Dom.: [GHS] Custom/...
catch’s picture

Status: Reviewed & tested by the community » Fixed

OK glad I asked! Worth having even if it just makes the test easier to read.

Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Wim Leers’s picture

Version: 9.5.x-dev » 9.4.x-dev
Status: Closed (fixed) » Patch (to be ported)

We should still get this committed to 9.4.x.

Wim Leers’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

#24 still applies cleanly to 9.4.x — queued a test to prove it passes tests.

  • catch committed 9034544 on 9.4.x
    Issue #3268306 by lauriii, Wim Leers, catch, Dom.: [GHS] Custom/...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.4.x, thanks!

Wim Leers’s picture

Version: 9.4.x-dev » 9.5.x-dev
Status: Fixed » Closed (fixed)

Restoring previous status.