Support the "name" attribute for backwards compatibility

Created on 6 November 2023, about 1 year ago

Problem/Motivation

For backwards compatibility sake, the module should support the "name" attribute, to ensure that existing content isn't broken.

Steps to reproduce

Have a node which had an anchor added via Anchor Link in ckeditor 4.
Edit the node after upgrading to ckeditor 5 / Anchor Link 3.

Proposed resolution

Allow the name="" attribute.

Remaining tasks

  • βœ… File an issue
  • βž– Addition/Change/Update/Fix
  • βž– Testing to ensure no regression
  • βž– Automated unit testing coverage
  • βž– Automated functional testing coverage
  • βž– UX/UI designer responsibilities
  • βž– Readability
  • βž– Accessibility
  • βž– Performance
  • βž– Security
  • βž– Documentation
  • βž– Code review by maintainers
  • βž– Full testing and approval
  • βž– Credit contributors
  • βž– Review with the product owner
  • βž– Release notes snippet
  • ❌ Release

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • N/A
✨ Feature request
Status

Active

Version

3.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @DamienMcKenna
  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    WIP, need to test to see if this covers it.

  • πŸ‡ΊπŸ‡ΈUnited States m-simmons

    I can confirm, `` gets removed while `` doesn't. Unfortunately the patch in #2 did not resolve the issue.

  • Status changed to RTBC about 1 year ago
  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I can confirm that on the same site mikesimmons has the tag does not work as expected. This specific project has editor_advanced_link, which might be interfering. That said, viewing content in ckeditor 5 with an old <a name=""> tag does not make it behave the same as clicking the anchor button and inserting a new anchor, so the plugin needs to be updated too.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    FWIW at this point I'm considering writing an update script to convert existing data and training people to use the id= attribute.

    Also related: ✨ Add "Anchor" button Needs work

  • πŸ‡¨πŸ‡¦Canada dylan donkersgoed London, Ontario

    A GitHub PR was opened for this at https://github.com/northernco/ckeditor5-anchor-drupal/pull/3. However, I'm not sure it's working. See the PR for details.

  • I've opened a new Github PR that I think addresses this issue:

    https://github.com/northernco/ckeditor5-anchor-drupal/pull/9

    Not sure if this implementation is the best way to go, but it seems to be working for me.

  • Status changed to Needs review 12 months ago
  • πŸ‡¨πŸ‡¦Canada dylan donkersgoed London, Ontario

    I've merged in mkimmet's fix and it seems to be working for me. It discovers anchor links with the name attribute set and converts them to id anchor links, but never saves links with the deprecated attribute. Please let me know if that's not suitable for your use case/if it's not working for you. It's on the 3.0.x branch currently, but drupal.org hasn't generated the composer release yet.

    This does not seem to require the patch from @DamienMcKenna, I think because it's not actually saving the attribute.

  • Thanks Dylan! Could we get a bump to 3.0.0-alpha2 (or some variation) on the list of releases on the project page with the new reference to the registry.npmjs.org ckeditor5-anchor-drupal-0.5.0.tgz? It seems when I reinstall the module I'm still getting 0.4.0 right now. Thanks!

  • Or maybe a bump to the dev version would be more appropriate, either way dev or alpha would work.

  • Status changed to Needs work 11 months ago
  • Moving to needs work, as I think think we need a new release on the for 3.0.x-dev (or alpha) which points to ckeditor5-anchor-drupal-0.5.0.tgz.

  • Status changed to Needs review 11 months ago
  • Thanks for updating the dev release Dylan! I did a test and it looks good to me. Moving back to Needs Review.

  • Status changed to Needs work 6 months ago
  • πŸ‡©πŸ‡ͺGermany dbielke1986

    alpha2 is not working for us.
    The name attribute will be removed as soon as the Anchor Link Module is activated :-(

  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Hi, @dbielke1986. Unfortunately, the updated library is only in 3.0.x-dev. It hasn't made it to a tagged release yet. Back to NR.

    On that note, we've been using dev for a couple months with no issues. I'd vote for RTBC.

  • Status changed to Needs work 6 months ago
  • πŸ‡©πŸ‡ͺGermany dbielke1986

    @justcaldwell

    Unfortunately, I cannot confirm this. I used the dev version of β€œDevelopment version: 3.0.x-dev updated 20 Dec 2023 at 17:25 UTC” and the name=" tag is removed.

  • πŸ‡§πŸ‡ͺBelgium joevagyok

    You can work around this by creating your own filter plugin to ensure name tag is maintained.

    class FilterAnchorLink extends FilterBase {
    
      /**
       * {@inheritdoc}
       */
      public function process($text, $langcode) {
        $result = new FilterProcessResult($text);
    
        $dom = Html::load($text);
        $xpath = new \DOMXPath($dom);
        foreach ($xpath->query('//a') as $node) {
          $href = $node->getAttribute('href');
          if (!empty($href)) {
            // If there is an "href" defined, we should not do anything.
            continue;
          }
          $name = $node->getAttribute('name');
          if (empty($name)) {
            // If there is no deprecated "name" defined, we should not do anything.
            continue;
          }
          $id = $node->getAttribute('id');
          if (!empty($id)) {
            // If there is an "id" defined, we should not do anything.
            continue;
          }
          $node->setAttribute('id', $name);
        }
        $result->setProcessedText(Html::serialize($dom));
    
        return $result;
      }
    
    }
    
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Thanks for clarifying, @joevagyok!

    That the name attribute doesn't survive the upcast is mentioned in a couple comments, so I updated the IS to clarify the proposed solution based on the current implementation.

    Also hiding the patch from #2, as it's not necessary given the current approach.

  • Status changed to RTBC 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    This seems to be working well β€” setting to RTBC. The library change for this issue actually shipped in the latest tagged release (3.0.0-beta1). So should it actually be marked as Fixed?

    I also tweaked the issue summary to further clarify that name attributes are supported, but won't appear in the markup for new or edited content.

    Regarding legacy content with only name attributes...

    If you have existing content with name attribute in the text, and you want to avoid big update path processing these texts, that needs to be converted to id attribute.

    Though name is deprecated, browsers tend to support obsolete markup for a very long time. I suspect that browsers will support "named anchors" into the foreseeable future. If that's the case, I'm not sure there's any requirement to update older content to convert names to ids (at least not for the purposes of this issue).

  • πŸ‡§πŸ‡ͺBelgium joevagyok

    I agree with @justcaldwell comment to move it into RTBC!

  • πŸ‡¬πŸ‡§United Kingdom Rob230

    How do I get this change into the module? I don't understand what the Github repo in PR #8 is for.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    @rob230 - this fix is actually included in the current release (3.0.0-beta1). The maintainers just haven't updated the issue status to Fixed.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Here to eat my words 😬.

    Given that there's still a large number of sites that haven't moved from CKEditor 4 (1.x and 2.x branch usage is still at ~18K), there may be a case for supporting an improved upgrade path that allows testing both CKE4 and CKE5 concurrently (see πŸ› Support concurrent use of CKEditor 4 and 5 Active ).

    This would require allowing the name to continue to appear in the final source code. As I wrote in that issue:

    The plugin currently upcasts anchors with name attributes, but does not include the name attribute in the resulting page source. As a result, anchor links that have been edited in CKEditor 5 will no longer be present if the text format is subsequently switched back to one using CKEditor 4.

    Even though name is deprecated, it might be preferable to continue full support for now, and remove it in a subsequent release or branch.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    As I indicate in the MR, this still requires minimal changes in northernco/ckeditor5-anchor-drupal plugin. I can open a PR there if there's any interest in this.

    At this point, we're just using a custom build of the plugin that resolves this and a few other issues in the queue to try to ensure a smooth transition from cke4 -> cke5.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    I opened PR 14 on northernco/ckeditor5-anchor-drupal in support of the MR here.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Static patch of the current MR.

Production build 0.71.5 2024