Problem/Motivation

Similar previous issue: #3274278: Migrate "codetag" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5.

#3263384: Add ckeditor5-code-block package and CodeBlock plugin added the CKEditor 5 CodeBlock to Drupal core's CKEditor 5 build. That means that https://www.drupal.org/project/codesnippet was largely obsolete. Which is why it has not seen movement in the past year at #3269387: Drupal 10 & CKEditor 5 support.

The two missing features in core compared to the https://www.drupal.org/project/codesnippet contrib module for CKEditor 4:

  1. The ability to configure which languages are available for the content creator to select from
  2. The ability to apply syntax highlighting

Steps to reproduce

  1. install and enable https://www.drupal.org/project/codesnippet
  2. Add the CodeSnippet button to a CKEditor-enabled text format:
  3. Configure it:
  4. Attempt to upgrade from CKeditor (4) to CKEditor 5. Also, notice the error that the button is not added:
  5. With the proposed patch, switching from CK4 to CK5 does not trigger warning, and the button is present in the same location in the toolbar. And it has the same configuration:

Proposed resolution

After #3263384: Add ckeditor5-code-block package and CodeBlock plugin landed, #3282233: Ability to configure additional languages (e.g. "bash" or "SQL") for CKEditor 5 CodeBlock plugin was opened. That landed yesterday. That means the first missing feature is now addressed.

That only leaves syntax highlighting. Drupal core should not do that. But … it really was also not a concern for a CKEditor plugin either! So I did the research (see #3269387-16: Drupal 10 & CKEditor 5 support) and found that there's two solutions available in contrib today:

  1. https://www.drupal.org/project/highlight_php — with #3287893-4: Automated Drupal 10 compatibility fixes applied
  2. https://www.drupal.org/project/highlightjs_input_filter — tested with version 1.0.1

Furthermore, syntax highlighting is only cosmetic — the text editor UX and the data model (stored markup) are unaffected by syntax highlighting absence/presence

That means that Drupal core should provide an upgrade path from https://www.drupal.org/project/codesnippet to Drupal core's CodeBlock plugin, just like we did in #3274278: Migrate "codetag" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

Sites switching a text format using CKEditor 4 with the https://www.drupal.org/project/codesnippet plugin enabled will automatically have their settings upgraded for an equivalent text editor user experience.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Status: Active » Needs review
FileSize
6.14 KB
Wim Leers’s picture

kevinquillen’s picture

#3 this looks good to me. I took an existing site, upgraded it to 10.1-dev with the patch. After logging in and changing my full html format to CKEditor 5, all of my CodeSnippet settings were preserved.

Wim Leers’s picture

And for context, @kevinquillen is the maintainer of https://www.drupal.org/project/codesnippet.

@kevinquillen, Care to RTBC? 😇

kevinquillen’s picture

Sure! Is there an indication in the admin of how to get highlighting (help doc?) working after switching from 4 to 5?

kevinquillen’s picture

Status: Needs review » Reviewed & tested by the community
quietone’s picture

Title: Follow-up for #3282233: migrate "codesnippet" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5 » Provides an upgrade path for "codesnippet" contrib CKEditor 4 plugin

Titles, an thus the commit message, don't need to include follow up information. I removed that and then further updated the title using text from the issue summary.

Wim Leers’s picture

Title: Provides an upgrade path for "codesnippet" contrib CKEditor 4 plugin » Provide an upgrade path from "codesnippet" contrib CKEditor 4 plugin to "CodeBlock" core CKEditor 5 plugin

@kevinquillen in #6:

Sure! Is there an indication in the admin of how to get highlighting (help doc?) working after switching from 4 to 5?

No. That's the one part that is A) missing, B) can not be done in core, only in contrib. Because Drupal core is not allowed to recommend contributed modules.

So … I suggest that you update the https://www.drupal.org/project/codesnippet project page with that information 😊


@quietone in #8: thanks! Tweaked the title slightly for clarity — hope you like it! 😊

kevinquillen’s picture

Will do!

mglaman’s picture

I also applied #3282233: Ability to configure additional languages (e.g. "bash" or "SQL") for CKEditor 5 CodeBlock plugin on my 9.5.9 site and this patch. The codesnippet migration patch in this issue worked great!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: 3356929-2.patch, failed testing. View results

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community

Random fail in InstallerExistingConfigSyncDirectoryMultilingualTest::testConfigSync after having been green for 11 days with daily re-testing 🤷

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: 3356929-2.patch, failed testing. View results

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated random failure in Drupal\FunctionalTests\Installer\InstallerExistingConfigMultilingualTest::testConfigSync

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

  • lauriii committed dd9c7183 on 11.x
    Issue #3356929 by Wim Leers, kevinquillen: Provide an upgrade path from...

  • lauriii committed bc4ffef3 on 10.1.x
    Issue #3356929 by Wim Leers, kevinquillen: Provide an upgrade path from...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed dd9c718 and pushed to 11.x. Thanks! Discussed with @catch and @longwave on Slack and decided to backport to 10.1.x as this helps sites update from CKEditor 4 to CKEditor 5.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Parashram’s picture

Failed to apply patch #2 at my end. Using drupal version "10.1.2"