Problem/Motivation

I use Drupal 10 and ckeditor 5, if I add a nbsp to a link, the link is split into two parts

for example :

before adding the nbsp : <a href="/"> content link </a>

after adding the nbsp : <a href="/">content&nbsp;</a>&nbsp;<a href="/"> link </a>

CommentFileSizeAuthor
#13 Capture d'écran 2024-06-04 090133.png18.05 KBdrunir

Issue fork nbsp-3432756

Command icon 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

luci_ole created an issue. See original summary.

wengerk’s picture

We utilize the insertContent function to inject HTML into CKEditor 5, which appears to be the recommended method for injecting model fragments (such as <nbsp>&nbsp;</nbsp>).

Referencing our implementation in the nbspCommand.js file.

However, we've encountered an issue where using insertContent within a link results in the link being split, as noted by @luci_ole.
Despite searching the CKEditor 5 documentation and the Github Issue Queue, we haven't found a solution to prevent this behavior.

Any assistance in resolving this issue would be greatly appreciated. If any maintainers or individuals are aware of modules or implementations that successfully insert HTML within a link in CKEditor 5, we would be eager to examine their approach.

wengerk’s picture

Status: Active » Needs review
wengerk’s picture

It was a schema issue as pointed by ksenzee on Slack https://drupal.slack.com/archives/C01GWN3QYJD/p1714662493560729?thread_t...

To solve the problem, I just changed the schema

    schema.register("nbsp", {
      allowWhere: '$text',
+      allowAttributesOf: '$text',
      isInline: true,
+      isObject: true
    });

  • wengerk committed 98cca115 on 3.0.x
    Resolve #3432756 "Splitting the links"
    
wengerk’s picture

Status: Needs review » Reviewed & tested by the community

Merged on dev branch 3.0.x

For people willing to use this fix before release of 3.0.2, please use the patch on Gitlab.

  • wengerk committed 4a319836 on 2.x/3432756-splitting-the-links
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed cc672f0d on 8.x-2.x
    fix issue #3432756: Splitting the links in two
    
wengerk’s picture

Status: Reviewed & tested by the community » Fixed

wengerk credited ksenzee.

wengerk’s picture

Give credit to ksenzee for helping me pointing the issue on Slack
https://drupal.slack.com/archives/C01GWN3QYJD/p1714637176482069

drunir’s picture

StatusFileSize
new18.05 KB

The test in #3 works fine, but when you add an "a" tag in wysiwyg, and add an "nbsp" tag inside it using the "non-breaking space" button, the "a" tag will be split !
nbsp

wengerk’s picture

Status: Fixed » Needs work

  • wengerk committed ca4c86e4 on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    
wengerk’s picture

Status: Needs work » Needs review

I've made a new batch of fix about how the command inject the nbsp tag. Should now propertly keep all AttributeElement and not break them (eg. breaking links).

  • wengerk committed 52073582 on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed 74915bef on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed 6a4c3664 on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed b8c85684 on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed 9410f9ed on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    

  • wengerk committed e85d2ef9 on 30x/fix-splitted-link
    fix issue #3432756: Splitting the links in two
    
wengerk’s picture

For thos willing to help reviewing the code, you can integrate this patch in a Drupal project using Composer & cweagans/composer-patches.

  1. Update your composer.json file to apply the patch.

      "extra": {
          "patches": {
            "drupal/nbsp": {
              "Splitting the links in two - 3432756": "https://git.drupalcode.org/project/nbsp/-/merge_requests/14.patch"
            }
          }
        }
      
  2. run the command composer update drupal/nbsp in order to apply the patch
  3. Review the changes in your Drupal UI
drunir’s picture

I tested the new patch, it works well for me, thanks @wengerk

wengerk’s picture

Status: Needs review » Reviewed & tested by the community

  • wengerk committed e85d2ef9 on 3.0.x
    fix issue #3432756: Splitting the links in two
    
wengerk’s picture

Thanks for testing it ! merged in 3.0.x (dev) will made a new release asap