Default highlight.css marker background color definitions are not loaded

Created on 7 September 2024, 3 months ago
Updated 21 September 2024, 2 months ago

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!

Feature request
Status

Postponed

Version

1.2

Component

Code

Created by

🇮🇹Italy kopeboy Milan

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

Comments & Activities

  • Issue created by @kopeboy
  • 🇮🇹Italy kopeboy Milan

    Ooops! I just noticed the provided highlight.css already includes exactly that CSS 😅

    So, the problem is that both in Olivero and Claro, they don't work somehow 🤔

    Tested on Chrome desktop and vanilla Drupal 10.3.2

  • 🇮🇹Italy kopeboy Milan

    It would still be possible to include the CSS on all pages by adding the library I guess, so changing this back to Feature request 😇

  • Status changed to Postponed 2 months ago
  • Hi 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.

  • 🇭🇰Hong Kong kc tang

    I 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.

  • 🇵🇱Poland salmonek

    Hi @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:

    .marker-yellow { background-color: #fdfd77; }
    .marker-green { background-color: #62f962; }
    .marker-pink { background-color: #fc7899; }
    .marker-blue { background-color: #72ccfd; }
    .pen-red { background-color: transparent; color: #e71313; }
    .pen-green { background-color: transparent; color: #128a00; }
    

    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...

  • 🇭🇰Hong Kong kc tang

    Thank 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:
    mark
    added

    How should I configure to enable them?

  • 🇵🇱Poland salmonek

    Hi @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.

  • 🇭🇰Hong Kong kc tang

    I 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?

Production build 0.71.5 2024