Problem/Motivation
It appears as if 'Limit allowed HTML tags and correct faulty HTML' fails to validate with the current <span> and <span style> configuration as seen in the ckeditor_font configuration.
When removing <span style> and leaving to just <span>, the functionality validates.
Can someone confirm that the 'Limit allowed HTML tags' breaks this validation on a text_format in CKEditor5?
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2024-01-08_11-58.png | 74.6 KB | heddn |
| #10 | ckeditor_font-n3358205-10.patch | 1.9 KB | damienmckenna |
Issue fork ckeditor_font-3358205
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
bmunslow commentedThat's correct,
filter_htmlfilter is incompatible with theckeditor_fontpugins (font size and font family), because the style attribute is not allowed.See:
Comment #3
mandras87 commentedI confirm the problem.
What are the possible workarounds ?
A clean during the paste ?
Use data attributes ?
Use class names ?
Comment #4
bmunslow commentedThe most straightforward workaround is obviously to disable the
limit_htmlfilter.Sadly, as far as I know, it's not really possible to transform the style attribute to class names in this case (although it is doable with the color button plugin, for instance).
The only option would be to develop your own custom font-size and font-family CKEditor5 plugins so they create and assign class names to style each element, instead of using the
styleattribute.CKEditor 5 Dev Tools would be a good starting point.
Comment #5
bgreco commentedHere's a workaround which changes the font plugin to generate
<span class="font-size-*">instead of<span style="font-size: *px">. You also need to create corresponding CSS rules to apply the font size to the font-size-* classes.Comment #6
damienmckennaShouldn't the system automatically add "style" as an allowed attribute for "span" as it's listed in the plugin's "elements" definition?
Comment #7
damienmckennaComment #8
wim leersSee #2 + #4.
The style attribute is never allowed by
filter_html. It’s an XSS-protection thing that cannot be disabled. It’s not related to CKEditor 5.What this does mean is that we should add even stricter validation to CKEditor 5 in Drupal core, which would inform the user that a particular plugin cannot be used while
filter_htmlis enabled!Could you please create an issue for that, @DamienMcKenna? 🙏
(Note that all of these restrictions ALSO existed in CKEditor 4, Drupal 7/8/9, but they were just quietly ignored — CKEditor 5's validation logic tries to catch every single incompatibility. This is one we didn't think about 😅.)
Comment #9
wim leersI was wondering why this isn't a more widespread problem. I'd SWEAR we prevented this in the CKEditor 5 admin UI! 😅
The answer:
and
These are the two only CKEditor 5 plugins in Drupal core that claim to support creating
styleattributes. Note that they both havea plugin condition like this:
That works in those cases, because they're automatically enabled enhancements for a manually enabled plugin/toolbar item ("Table").
But this is a different case. In this case, we need to have a validation error triggered whenever
filter_htmlis enabled and we're trying to add this plugin by adding a toolbar item.On top of that, we need to expand the validation logic in
\Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateDrupalAspects()to inform plugin developers that whenever they specify thestyleattribute, thatckeditor5_arbitraryHtmlSupportMUST be explicitly listed as a plugin condition.Once those 2 things are done in Drupal core, this confusing behavior will no longer be possible, and the UX will be great again 🤓
Comment #10
damienmckennaSo something like this?
Comment #11
damienmckennaThe bug here is that the plugin and UI need to direct the site builder to configure the site appropriately.
Comment #12
damienmckennaWim: Does #3384594: Disallow the "Limit allowed HTML tags" filter when a ckeditor plugin requires ckeditor5_arbitraryHtmlSupport work as a core issue to improve this UX?
Comment #13
wim leersActually, there may be a simpler solution that satisfies more people:
https://www.drupal.org/project/extended_html_filter was created for literally this purpose: it's
filter_html, but with thestyleattribute allowed.It was still a bit rough around the edges though, so created a MR to smoothen that out: #3401513-3: Match the filter_html <> ckeditor5 integration in Drupal core.
Comment #14
heddnOn 10.2+, the additional validation for ck5 attributes and properties is getting in the way. I attempted to use extend_html_filter and the the MR from #3401513: Match the filter_html <> ckeditor5 integration in Drupal core and still no joy.
Comment #15
heddnThe error that comes from this module is attached:
Comment #16
lawxen commentedSame problem with #15 with
Comment #17
greenskin commentedI like the idea of #5 but need it for setting a font color class but the "view" option doesn't appear to work for fontColor. We try to use Tailwind CSS for our themes and would love the option to apply these style options (font, size, color, etc) as classes.
Comment #20
goz commentedMR35 reroll patch so it applies on 2.0.0-beta6
Comment #21
danrodComment #22
danrodComment #23
danrodComment #24
jwilson3Fix issue summary HTML code readability.
Comment #25
danrodI'll post some screens before and after the patch, but It did not work for me for some reason.