Open Mgsy opened 2 years ago
The inner link (<a rel>
) is outputted by GHS. The outer one by the automatic decorator. Those two aren't merged together because there's a conflict - both use the rel
attribute.
It should happen here:
We treat only class
and style
granularly and merge them. See:
All other attributes are not merged and prevent merging elements.
Related issue: ckeditor/ckeditor5#6436.
The problem is that the logic to treat these attributes granularly would need to change in several places. A bit like the history with StylesProcessor
that is now widely used in the view logic. In other words, this would be a big change to make rel
work granularly.
Additionally, we'd need to make this extensible, just like we did with StylesProcessor
. Here we have a problem with rel
, but what if someone expected data-rels
to also work granularly?
This issue can be reproduced using the Manual decorator using below steps
Create ckeditor from sources (https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/quick-start-other.html#building-the-editor-from-source)
Add Link, GHS and SourceEdit plugins.
In the app.js file add below Link and GHS configuration and rebuild it
link: {
decorators: {
openInNewTab: {
mode: 'manual',
label: 'Open in a new tab',
defaultValue: true,
attributes: {
target: '_blank',
}
}
}
},
htmlSupport: {
allow: [
{
name: /.*/,
attributes: true,
classes: true,
styles: true
}
],
}
Open index.html, in the editor using the Link plugin create link for http://www.google.com/
Click Source button and we see below
<a href="http://www.google.com" target="_blank">Link</a>
In source Mode change the target from _blank
to _self
Exit Source Mode
Edit the link in Normal mode (WYSWIG ) and observe the βOpen in a new windowβ is toggled to off, which is expected.
Now toggle it to ON to make the link open in new tab.
Click on the Source Button and we see the link has been divided (even though we don't use rel
here
@Reinmar I think issue is with not only rel
, probably with target
also
Another example, where it will fail with existing data for manual decorator (created using above my previous comment)
<a href="http://www.google.com" target="_self">Link</a>
<a href="http://www.google.com" target="_self"><a target="_blank">Link</a></a>
I think this will be major issue, If some one edits the link through link plugin on existing data.
π Provide detailed reproduction steps (if any)
addTargetToExternalLinks
configuration.rel
attribute, e.g.editor.setData('<a href="https://google.com" rel="test">Foo</a>')
.editor.getData();
.β Actual result
The link has been divided:
<a target="_blank" rel="noopener noreferrer" href="https://google.com"><a rel="test">Foo</a></a>
.If you'd like to see this fixed sooner, add a π reaction to this post.