ckeditor icon indicating copy to clipboard operation
ckeditor copied to clipboard

CKEditor diverting the Link Open in a new tab, all the links back to toggle 'off

Open pbmills opened this issue 1 year ago • 1 comments

Description

I'm sliding the toggle to 'on', hitting the tick and it looks like job done, but when I save, it's diverting all the links back to toggle 'off' and links aren't opening in a new tab.

Steps to reproduce

  1. Clicking the Link and turning the toggle ON.
  2. Saving the Entry.

Screenshot 2024-08-12 at 8 50 53 AM

CKEditor -> Javascript [Config options].

return {
  link: {
      decorators: {
        openInNewTab: {
            mode: 'manual',
            label: 'Open in a new tab',
            attributes: {
                target: '_blank',
                rel: 'noopener noreferrer'
            }
        }
    }
  }
}

Additional info

  • Craft version: 5.2.10
  • PHP version: 8.2
  • Plugins & versions: CKEditor [4.1.0]

pbmills avatar Aug 11 '24 20:08 pbmills

I ran into the same issue, this is more a ckeditor bug for a long time https://github.com/ckeditor/ckeditor5/issues/12394

Our workaround is to remove the rel in the config.

options:
  link:
    decorators:
      openInNewTab:
        attributes:
          target: _blank
        label: 'Open in a new tab'
        mode: manual

By default the htmlpurifier adds the rel noopener, noreferrer on save with the settings HTML.TargetNoopener and HTML.TargetNoreferrer which are default true, you can add these settings also to be sure. I added the following to my config/htmlpurifier/Default.json

{
  "Attr.AllowedRel": [
    "noopener",
    "noreferrer"
  ],
}

http://htmlpurifier.org/live/configdoc/plain.html

Also you don't see the rel when using the source button in the ckeditor, but if you view the text on your site it is actually added. https://github.com/craftcms/ckeditor/issues/263

jeroenlammerts avatar Aug 12 '24 08:08 jeroenlammerts