Problem/Motivation
CKEditor has an AutoLink plugin that converts URLs into links.
It runs after pressing enter or space when the cursor is at the end of a url.
The text filter also has an option to convert urls into links, with a trim length.
You can trick AutoLink by navigating away with the arrow keys.
Steps to reproduce
Paste a long url and press enter.
Then paste the url again and save.
You should see the link with and without the trim length.

Proposed resolution
In FilterUrl, check for links that have the same text and url.
This will trim links that were previously converted, which may impact sites. However, I suspect there are far more people doing this by accident vs using the trick to paste long or trimmed urls. A better way would be to use a class or setting to skip the trim in a link.
1. trimExistingLinks() parses text for links to check and calls isUrlOfLink().
2. isUrlOfLink() checks if a link's url matches it's text using the same conversion as ckeditor's autolink.
3. isInIgnoredTag() skips links inside code, pre, script, style tags.
Remaining tasks
Discuss impact, decide if flag or setting is needed to skip.
Review MR.
User interface changes
Behavior in CKEditor remains the same, but using the trick to apply the trim length is no longer needed.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot 2026-11-15 at 18-14-13 Colors Mantra Theme.png | 16.28 KB | mortona2k |
Issue fork drupal-3638764
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:
Comments
Comment #2
mortona2k commentedComment #4
mortona2k commentedI used AI for the MR. The change is fairly compact reads well to me. But it involves regex and processing formatted text, which I'm not too familiar with.
This uses the same url conversion as ckeditor autolink to check if the text matches.
If this is too disruptive to existing content, we could add an option to skip links and only convert bare urls, as it currently works. If we really want to use both options on a site, maybe the ckeditor link plugin could have an option to shorten url text when pasted, or a setting per link.