Problem/Motivation
When a site builder enables ckeditor5_plugin_pack_highlight he doesn't get the expected result. As you already explained in the docs, the markers will all show as yellow (or whatever the default style of your browser is).
Even if explained both in the documentation and text format config page, I think it would be very useful to provide the defaults so that the Highlight feature works out-of-the-box.
Having to supply custom CSS is not trivial in Drupal. For example I was preparing a recipe that was including this plugin pack: I can ship all the needed & default configuration and content templates I want, but I cannot provide CSS (you need a custom module or theme for that).
This module is a great showcase of CKEditor features (thank you!!), and thus I think it will have a much bigger impact if we apply this philosophy of working out-of-the-box that will also be made popular by the coming Drupal Starshot.
Proposed resolution
CKEditor already loads this CSS with any theme:
:root {
--ck-highlight-marker-yellow: #fdfd77;
--ck-highlight-marker-green: #62f962;
--ck-highlight-marker-pink: #fc7899;
--ck-highlight-marker-blue: #72ccfd;
--ck-highlight-pen-red: #e71313;
--ck-highlight-pen-green: #128a00;
}
Hence we just need to include in the ckeditor5_plugin_pack_highlight submodule a library with this CSS:
.marker-yellow { background-color: var(--ck-highlight-marker-yellow); }
.marker-green { background-color: var(--ck-highlight-marker-green; }
.marker-pink { background-color: var(--ck-highlight-marker-pink; }
.marker-blue { background-color: var(--ck-highlight-marker-blue; }
.pen-red { background-color: transparent; color: var(--ck-highlight-pen-red; }
.pen-green { background-color: transparent; color: var(--ck-highlight-pen-green; }
Anyone that will later add CSS with his own library as suggested in the docs and in the text format config page, like .marker-green { background-color: #62f962; }, will have their style override the default. Hence no problems, just benefits!
Issue fork ckeditor5_plugin_pack-3472711
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
kopeboyOoops! I just noticed the provided highlight.css already includes exactly that CSS 😅
Btw, since the variables are defined in the same file (and I guess they are not used anywhere) the
highlight.csscould be improved to directly define the colors (like suggested in the text format config page 😇)So, the problem becomes that the highlight.css won't be included on pages that don't have a form with CKEditor..
Comment #3
kopeboyOne could use the editor on any text field, that can be shown anywhere on the site, and marker colors are pretty general and lightweight, so the CSS library could be loaded on all pages of the site... but I guess it's still better to include it in a theme instead of in this .module?
Comment #4
mdusza commentedHi kopeboy!
Thanks for reaching out.
We consider current behaviour the expected one and we haven't had plans to change it so far, as giving flexibility to our users was our main motivator here. We appreciate the fact that adding custom CSS might be non-trivial for some users, but at the same time it's not something too complex for most Drupal admins in our opinion.
However, we are open to feedback and we'll keep the issue active for some time to see if there will be more demand for such change and we'll consider it based on that.
Comment #5
kc tang commentedI have encountered the same problem. The above issue has been marked as "postponed".
It seems that the Proposed Resolution posted above was after some prior discussions not shown above. I cannot comprehend the full story, May I have more explanation of how to resolve the problem, i.e. how to configure it.
Comment #6
salmonek commentedHi @kc-tang
Thank you for your feedback, having more requests here will encourage us to reconsider possibility of adding highlight styles automatically.
In the meantime you can display various marker colors in the frontend theme by adding css rules to your theme's styles:
If you would like to use only default CKEditor 5 markers then simply add:
Or since the CKEditor variables are added to frontend themes globally then you can use css rules which @kopeboy posted in the issue's description.
In case you would like to use custom colors please check our guide at https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib...
Comment #7
kc tang commentedThank you for the direction!
I use the Bartik theme. I have similar codes in my print.css borrowed from the previous "ckeditor5 highlight" module, and have added them to .../web/themes/contrib/bartik/css/layout.css:
mark.marker-blue {
background-color: hsl(201, 97%, 72%);
}
mark.marker-green {
background-color: hsl(120, 93%, 68%);
}
mark.marker-pink {
background-color: hsl(345, 96%, 73%);
}
mark.marker-yellow {
background-color: hsl(60, 97%, 73%);
}
mark.pen-blue {
background-color: inherit;
color: hsl(201, 97%, 72%);
}
mark.pen-green {
background-color: inherit;
color: hsl(112, 100%, 27%);
}
mark.pen-red {
background-color: inherit;
color: hsl(0, 85%, 49%);
}
The highlighting is now working. Previously, the highlighting was working when in the edit mode or in the printer-friendly mode, but not working in the view mode.
For the resolution suggested by @kopeboy, may I know which file to edit to add the settings?
By the way, I would like to report that the same problem and phenomenon happen with the Font Colour icon.
The following codes cannot work out:
How should I configure to enable them?
Comment #8
salmonek commentedHi @kc-tang
Sorry for long response, I was on vacation last week.
The kopeboy's rules should work also when placed in layout.css file
Font colour uses "style" property which is filtered out by "Limit allowed HTML tags and correct faulty HTML" filter in the text format settings. It will work only without that one.
Comment #9
kc tang commentedI confirm that I had that unchecked before and now. The highlighted font cannot display when in view mode. Which configuration files might have been disturbed?
Comment #10
salmonek commented@kc_tang
Sorry for long response. It's not a matter of configuration, but attaching a styles to theme. If you use bartik then indeed it is not as easy as adding styles in custom theme. It would require to add a custom css library in custom module and attach it in a preprocess function.
I'll push a MR soon which will add such option in the text format configuration.
Comment #12
salmonek commentedMR added. Patch adds an option to attach styles to all pages. It is located in text format settings in same place where custom colors are defined. On form submit if checkbox is checked there will be created a file in
public:/ckeditor5/directory.Then when libraries are assembled for each text format having attach styling selected there will be created a dynamic css library which will be attached to every page.
A cache rebuild will be required after saving a text format, however I suppose I could add a css librsries flush in code.
Comment #13
salmonek commentedComment #14
salmonek commentedTested by our QA team, merged and will be added to the next release.
Comment #15
salmonek commentedFeature has been released in 1.3.1
Comment #17
jwag956 commentedI believe the solution implemented doesn't work in a normal drupal development cycle. The solution is creating a piece of content (the .css file) when the form is saved. But the form (text formats) is saved as part of configuration so on a development machine, the first time the form is saved the new css file is created - but when pushing configuration to production the css content file won't be created.
I would also suggest that having per-text-format highlighting color/class and style configuration doesn't make much sense and complicats all this considerably - the viewer of the content has no idea how it was created. It would seem a really simple answer is to always include the highlight.css library when Highlight plug-in is enabled.
Comment #18
dallen33 commentedYes the way this is implemented does not work for our Drupal deployments.
Locally I enabled the "Add styles for rendered content automatically" setting, this creates the
public://ckeditor5folder with the following files:Then I do a
drush config:exportand try to deploy my changes to our production environment. Unfortunately, I get an error.Mon Mar 23 11:57:27.630989 2026] proxy_fcgi:error] pid 84:tid 138212424054528] client 127.0.0.1:55590] AH01071: Got error 'PHP message: Uncaught PHP Exception TypeError: "file_exists(): Argument #1 ($filename) must be of type string, bool given" at /var/www/html/web/modules/contrib/ckeditor5_plugin_pack/modules/ckeditor5_plugin_pack_highlight/ckeditor5_plugin_pack_highlight.module line 49'On line 47:
\Drupal::service('file_system')->realpath()returnsfalsewhen the path doesn't exist - specifically when thepublic://ckeditor5/directory hasn't been created yet on the production server.realpath()only returns a string path if the file/directory actually exists on disk. Since the deployment is a fresh environment (or theckeditor5/subdirectory hasn't been created),realpath()returnsfalse, which then gets passed tofile_exists()on line 49 - triggering the TypeError.Should
ckeditor5_plugin_packbe checking for/creating the directory before callingrealpath()?Comment #19
salmonek commentedYup, this sounds definetely like a thing we need to add. Thank you for detailed info.
Comment #20
salmonek commentedAh, re-closing. I didn't notice new issue at first. Wanted to re-open, then noticed the new ticket and forgot to change back the option here :(