CKEditor 5 moves some classes in the a tag

Created on 25 November 2024, 26 days ago

Problem/Motivation

CKEditor 5 moves the “glightbox” class to another position.

Steps to reproduce

- In the source code I insert:

<!-- Simple image -->
<a href="large.jpg" class="glightbox">
<img src="small.jpg" alt="image" />
</a>

- I save, check the source code and find:

<!-- Simple image -->
<a href="large.jpg">
<img class="glightbox" src="small.jpg" alt="image">&nbsp;
</a>

CKEditor moved the glightbox class from the first to the second image and added &nbsp at the end.

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

ckeditor5.module

Created by

🇮🇹Italy giordy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @giordy
  • I can't seem to reproduce this. Please add the complete steps to reproduce to the issue summary. Using a site like https://simplytest.me is a way to create a clean Drupal site for bug reproduction.

    Also, see if you can reproduce the bug with the CKEditor 5 demo so we can understand if this is CKEditor or a Drupal filter causing it.

  • 🇮🇹Italy giordy

    1. https://simplytest.me/ does not work: There was a build error 60%
    2. CKEditor 5 demo: the problem does not reproduce.
    3. I create the page https://prova.gmpe.it/tettonica/attivita-sismica-vulcanica
    4. In the source code I insert:

    <p class="text-align-center">
    <a class="glightbox" href="/sites/default/files/tettonica/tectonics_map.gif"><img src="/sites/default/files/tettonica/vulcani.png" width="651" height="223"></a>
    </p>

    5. I save.
    6. I check the source code:

    <p class="text-align-center">
    <a href="/sites/default/files/tectonica/tectonics_map.gif"><img class="glightbox" src="/sites/default/files/tectonica/vulcani.png" width="651" height="223"></a>
    </p>

    7. The problem occurs in all pages with the glightbox class
    8. In text formats there are no filters for glightbox

  • I continue not to be able to reproduce this bug. Here is what it did:

    1. Installed a new Drupal 11 site.
    2. Added an article.
    3. For the body field I selected Text Format: Full HTML.
    4. I switched the editor to source mode.
    5. I pasted the HTML given in the issue summary.
    6. I saved the node.
    7. I examined the HTML. There are no changes.
    8. I edited the node.
    9. I switched the editor to source mode.
    10. I examined the HTML. There are no changes.

    Because you have a site that can reproduce the bug we need much more detail about how CKEditor and the text formats are configured.

  • 🇮🇹Italy giordy

    Attached are the images of the buttons and filters, unfortunately in Italian, of full_html.

    Instead of modifying the existing pages, I repeat the procedure on a new page: https://prova.gmpe.it/prove.

    1. I insert an image with IMCE
    2. I connect the image with another image
    3. In the link I put the glightbox class
    4. I save and check if it works: html has not changed
    5. In the same page I copy the code of another page that originally had colorbox
    6. I replace colorbox with glightbox
    7. I save and check if it works: html has changed, the class has been moved from the link to the image

    In the same page I have two images, one works and the other does not. Absurd!
    Practically, it only works on new images and not on existing ones.
    Unfortunately I have to replace all the colorbox in the site with glightbox because Colorbox Inline module it looks like it won't be there for drupal 11.

    Thanks for your patience

  • 🇮🇹Italy giordy

    I found the problem: it's the p tag

    It works if I put:

    <a class="glightbox" href="/sites/default/files/tettonica/tectonics_map.gif"><img src="/sites/default/files/tettonica/vulcani.png" data-entity-uuid="" data-entity-type="file" alt="distribuzione di vulcani e terremoti" width="651" height="223"></a>

    If instead I put:

    <p class="text-align-center">
    <a class="glightbox" href="/sites/default/files/tettonica/tectonics_map.gif"><img src="/sites/default/files/tettonica/vulcani.png" data-entity-uuid="" data-entity-type="file" alt="distribuzione di vulcani e terremoti" width="651" height="223"></a>
    </p>

    CKEditor moves the class and shows the wrong image:

    <p class="text-align-center">
    <a href="/sites/default/files/tettonica/tectonics_map.gif"><img class="glightbox" src="/sites/default/files/tettonica/vulcani.png" data-entity-uuid="" data-entity-type="file" alt="distribuzione di vulcani e terremoti" width="651" height="223"></a>
    </p>

    Unfortunately without the p tag I don't know how to center the images.

    Thanks and best regards

  • 🇮🇹Italy giordy

    I found a way to center the images, so the problem is circumvented by avoiding putting the p and div tags.

    Kind regards

Production build 0.71.5 2024