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:
- The ability to configure which languages are available for the content creator to select from
- The ability to apply syntax highlighting
Steps to reproduce
- install and enable https://www.drupal.org/project/codesnippet
- Add the
CodeSnippet
button to a CKEditor-enabled text format: - Configure it:
- Attempt to upgrade from CKeditor (4) to CKEditor 5. Also, notice the error that the button is not added:
- 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:
- https://www.drupal.org/project/highlight_php — with #3287893-4: Automated Drupal 10 compatibility fixes applied
- 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.
Comment | File | Size | Author |
---|---|---|---|
#3 | Screenshot 2023-04-27 at 6.21.39 PM.png | 312.27 KB | Wim Leers |
#3 | Screenshot 2023-04-27 at 6.20.16 PM.png | 301.16 KB | Wim Leers |
#3 | Screenshot 2023-04-27 at 6.18.25 PM.png | 193.36 KB | Wim Leers |
#3 | Screenshot 2023-04-27 at 6.17.41 PM.png | 95.74 KB | Wim Leers |
#2 | 3356929-2.patch | 6.14 KB | Wim Leers |
|
Comments
Comment #2
Wim LeersComment #3
Wim LeersComment #4
kevinquillen CreditAttribution: kevinquillen at Velir commented#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.
Comment #5
Wim LeersAnd for context, @kevinquillen is the maintainer of https://www.drupal.org/project/codesnippet.
@kevinquillen, Care to RTBC? 😇
Comment #6
kevinquillen CreditAttribution: kevinquillen at Velir commentedSure! Is there an indication in the admin of how to get highlighting (help doc?) working after switching from 4 to 5?
Comment #7
kevinquillen CreditAttribution: kevinquillen at Velir commentedComment #8
quietone CreditAttribution: quietone at PreviousNext commentedTitles, 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.
Comment #9
Wim Leers@kevinquillen in #6:
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! 😊
Comment #10
kevinquillen CreditAttribution: kevinquillen at Velir commentedWill do!
Comment #11
mglamanI 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!
Comment #13
Wim LeersRandom fail in
InstallerExistingConfigSyncDirectoryMultilingualTest::testConfigSync
after having been green for 11 days with daily re-testing 🤷Comment #15
Wim LeersUnrelated random failure in
Drupal\FunctionalTests\Installer\InstallerExistingConfigMultilingualTest::testConfigSync
Comment #19
lauriiiCommitted 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.
Comment #21
Parashram CreditAttribution: Parashram commentedFailed to apply patch #2 at my end. Using drupal version "10.1.2"