Problem/Motivation
Discovered in #3246169: Embedded media are not linkable through UI; already linked embedded media are unlinked (data loss!).
See https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkConf... and https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkDeco....
Try this by applying
diff --git a/ckeditor5.ckeditor5.yml b/ckeditor5.ckeditor5.yml
index f6eaf90..80467ef 100644
--- a/ckeditor5.ckeditor5.yml
+++ b/ckeditor5.ckeditor5.yml
@@ -224,6 +224,9 @@ ckeditor5_link:
ckeditor5:
plugins:
- link.Link
+ config:
+ link:
+ addTargetToExternalLinks: true
drupal:
label: Link
library: ckeditor5/ckeditor5.link
Now every link you create that matches ^(http|//)
will get target="_blank" rel="noopener noreferrer"
applied.
This feature makes a ton of sense in CKEditor 5, where the generated HTML is the served HTML. But it does not make sense in Drupal, where we prefer not storing (hardcoding) such decisions in the database, and instead filter it on output, using the filter system.
For this example, the Drupal equivalent is https://www.drupal.org/project/extlink.
Steps to reproduce
See above.
Proposed resolution
Disable CKEditor 5's automatic decorators entirely, both on server (done) and client (TODO).
Remaining tasks
Discuss with CKEditor 5 team to determine best approach.Done. Conclusion: throwing an exception when automatic decorators are configured, both in PHP and in JS.Prevent automatic link decorators on server side.- Prevent automatic link decorators on client side.
Test coverage for automatic link decorators being prevented on server side.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#45 | 3247683-45-10x.patch | 85.08 KB | bnjmnm |
| |||
#45 | 3247683-45-93x.patch | 85.26 KB | bnjmnm |
Issue fork drupal-3247683
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Issue fork ckeditor5-3247683
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3247683-link-decorators changes, plain diff MR !160
Comments
Comment #4
Wim LeersComment #6
Wim LeersDiscussed during last week's CKEditor 5 meeting. @lauriii, @Reinmar and I agreed on an approach.
Comment #7
Wim LeersComment #9
Wim LeersExplicit test coverage for manual link decorators on
<img>
(still to do:<drupal-media>
) added. It doesn't work correctly in any of the 4 image linkability cases, not even in the case where Drupal does not intervene at all: the linked inline image case.Expected test output:
Comment #10
Wim LeersUpdate IS to clarify what work remains here.
Comment #11
Wim LeersTransfering the MR…
Comment #14
Wim LeersHm … none of my recently pushed commits are listed here… 🤔
Drupal core merge request 1418 definitely does have the equivalent of CKEditor 5 merge request 160 now (just with the
phpcs
"fix" commit applied to the commits where the violations were introduced).Comment #15
Wim LeersReported this in
#drupal-infrastructure
in Drupal Slack: https://drupal.slack.com/archives/C51GNJG91/p1637073092169800Comment #16
Wim LeersYay, https://github.com/ckeditor/ckeditor5/issues/10828 has been fixed upstream! Should be in the next release, December 7.
We should try this with the latest upstream CKEditor 5, to see if this then passes more tests. But … then we first need tests to actually work again 😳 I'm working with the Drupal Association to figure this out…
Comment #17
Wim LeersComment #18
Wim LeersSeems like it's pretty complicated to pin to a specific commit of a package in
package.json
😬Comment #19
Wim LeersThe problem is that the specific commit does get installed, but npm/yarn then inspect the
package.json
in that specific checkout.Solution per @Reinmar: use
yarn workspaces
:yarn workspaces
, like so: https://github.com/ckeditor/ckeditor5/blob/master/package.json#L192, pointing to the code checked out in step 1.yarn install
will then first look in that locally available checkout instead of using the external repository of npm modules@lauriii understands this better than I do, so together we should be able to figure it out :) The downside is that each person working on an MR will have to repeat some of these manual steps.
Comment #21
Wim LeersRather than going through the painful and uncertain process in #19, in the meantime a new version of CKEditor 5 was released that includes the commit this MR needs.
So we can instead wait for #3258250: Update to CKEditor5 v31.1.0 to land.
Comment #22
Wim Leers#3258250: Update to CKEditor5 v31.1.0 is itself blocked on #3258371: fix yarn vendor-update command — updating title.
Comment #23
Wim LeersBoth #3258371: fix yarn vendor-update command and #3258250: Update to CKEditor5 v31.1.0 landed, this is now unblocked!
Self-assigning since I last worked on this.
Comment #24
Wim LeersI'm pretty sure this is stable-blocking.
Comment #25
Wim Leers#3248228: Unable to change selection after linking inline media when manual decorators have been defined is adding a
core/modules/ckeditor5/tests/modules/ckeditor5_manual_decorator_test
test module that is far better than the one I wrote for this MR. Let's wait for that MR to land first.Comment #26
Wim Leers#3248228: Unable to change selection after linking inline media when manual decorators have been defined landed, which means this is unblocked.
Comment #27
catchOne question here. Drupal's URL filter has historically caused a lot of problems. Quite a lot of this was fixed in #161217: URL filter breaks generated href tags but it can still cause unpredictable bugs with other modules from what I've seen.
I think it would be good to eventually discourage it in favour of encouraging URLs to be explicitly linked in content, does this de-emphasise that option, or is it just the target="_blank" and similar?
Comment #28
Wim LeersAhh! This explains a lot, I was really surprised that
filter_url
generally works okay with CKEditor 4 and 5. (We recently refined the upgrade path to not complain loudly when you're usingfilter_url
in #3273312: Upgrading from CKEditor 4 for a text format that has FilterInterface::TYPE_MARKUP_LANGUAGE filters enabled).+1
This is 100% unrelated to/independent of
filter_url
.But it is related to additional filters, and the fact that we want to encourage/emphasize that over using CKEditor 5 magic, because that is not guaranteed to bring equally consistent results.
target="_blank"
for external URLstarget="_blank"
or set thedownload
attributeSee https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkConf....
The issue title says
→ the point is thattarget="blank_"
getting auto-added should not happen inside CKEditor 5, but should happen during Drupal's filtering, through a@Filter
plugin.Comment #29
catchOK so the ckeditor filters are adding attributes to
<a>
tags, but it's not affecting anything about turning a plain text URL into a link in the first place. Thanks for explaining, and agreed we don't want automated messing with attributes from ckeditor.Comment #30
Wim LeersPerfect, glad we’re on the same page! 😄
I forgot to ask earlier: what *are* those problems you are still seeing with using filter_url?
Comment #31
catch@WimLeers I've seen issues with the footnotes filter, but haven't had a chance to simplify anything to be reproducible yet. When I get a chance I'll try to do that and post a bug report somewhere.
Comment #33
Wim LeersI think this needs to start a new merge request — part of the current MR (manual decorator test coverage) already landed in #3248228: Unable to change selection after linking inline media when manual decorators have been defined — see #25.
That'll be easier than updating this one. You can still copy some parts of it over though :)
Comment #35
Wim LeersHm, maybe #3248228 only landed explicit manual link decorator test coverage for Media, not for Images.
Comment #37
lauriiiDo we need test coverage for the image manual link decorators since AFAIK that would be simply testing upstream functionality? I guess we could do that since we are making changes to the linked block image downcast. Either way I think that could be a follow-up.
Comment #38
Wim LeersI think that's reasonable.
The stable blocking piece here is that we want to ensure not a single Drupal site starts using automatic link decorators, because forbidding that in the future would be a backwards compatibility break once
ckeditor5.module
is stable.Retitling.
This actually makes the scope a lot clearer! 🥳
Comment #39
Wim LeersFor #37. That follow-up won't be stable-blocking.
Comment #40
Wim LeersThis looks great, but one part is not yet done:
But … after this many months since I looked at the details, I actually do not recall how one could set up automatic link decorators client side?
I think the idea is that you could modify
drupalSettings.editor
— either on the client side through JS or on the server side throughhook_js_settings_alter()
.To catch that, we could add detection logic in
core/modules/ckeditor5/js/ckeditor5.es6.js
. But thinking about that now, that seems fairly extreme. That'd also violate the separation of concerns: we'd make the generic CKEditor 5 instantiation logic tightly coupled to thelink
plugin. That seems disproportionate? 🤔So I would be fine with omitting that part.
Thoughts?
Comment #41
lauriiiI added an exception to the Drupal Media plugin as a DX improvement since that's the part which isn't compatible with automatic link decorators. I'm wondering if it would be a bit excessive to write test coverage for that 🤔
Comment #42
Wim LeersI think it would be.
Let's run all tests now!
Comment #43
bnjmnmPretty much just a nit, but switching to NW for visiblity. Seems like a clear cut "ok to self-RTBC"
Comment #44
lauriiiOpened follow-up for #37: #3284271: Add test coverage for manual link decorators image integration.
Comment #45
bnjmnmComment #50
bnjmnmLooks good, and preventing automatic link decorators like this is a good call. Committed to 10.0.x, 9.5.x and cherry picked to 9.4.x, 9.3.x.
Comment #52
sanci91 CreditAttribution: sanci91 commentedSorry, but how am I supposed now on Ckeditor5 on Drupal to add the option to links to have the target _blank?
With some config .yml? There is some setting I'm missing on admin/config/content/formats/manage/rich_text page?
I cannot figure out how to make links open in a new tab.
Thanks