Hi,
Here is my config :
Drupal 9.5.0
Theme : Bootstrap 5

I've activated CKEditor 5 to replace V4 then selected it in text format. But when I edit a content, I lose some inline style.
For example :
<span style="font-weight:600">This is bold text</span>
becomes :
<strong>This is bold text</strong>

This is only an example, I know semantically talking "strong" can replace "font-weight". But I don't dare editing all my other contents or I might lose other inline style more important which would break the pages.

How can I prevent this ? it was working fine in CKEditor 4.
Tanks.

Comments

Lucky723 created an issue. See original summary.

cilefen’s picture

Priority: Major » Normal
wim leers’s picture

Status: Active » Postponed (maintainer needs more info)
  1. What text format are you using?
  2. Can you please provide the exported config for both the text format and the associated text editor?
lucky723’s picture

@Wim Leers

1. I've created a personnalized text format from FULL HTML, to not change the default one.
2. Which commands should I run exactly to answer you ?

Thx

wim leers’s picture

drush cex <the ID of your text format> + drush cex <the ID of your text editor>

le72’s picture

With enabled "Limit allowed HTML tags and correct faulty HTML" filter you can't have style attribute.

svdhout’s picture

We use the style plugin to add inline styles, like this:

span.highlight|Highlight

Saving the editor configuration throws the following error

The Style plugin needs another plugin to create <span>, for it to be able to create the following attributes: <span class="highlight">. Enable a plugin that supports creating this tag. If none exists, you can configure the Source Editing plugin to support it.

Which is correct, because we do not have a plugin defining that we can use span tags.
The approach for adding the source editing plugin works, and allows me to add the styling i want.

However, i do not really like having to add the Source editing plugin for this.

I can solve the problem in a module by adding this configuration inside a .ckeditor5.yml file:

ckeditor5_span_span:
  ckeditor5:
    plugins:
      - essentials.Essentials
  drupal:
    label: Span
    library: core/ckeditor5.essentials
    admin_library: ckeditor5/internal.admin.essentials
    elements:
      - <span>

Is allowing span tags something we want to do in core, or would it be best to create a contrib module for this?

wim leers’s picture

However, i do not really like having to add the Source editing plugin for this.

That's the only way, sorry.

I can solve the problem in a module by adding this configuration inside a .ckeditor5.yml file:
[…]

Is allowing span tags something we want to do in core

Clever work-around for your particular use case! 😄 But that now means you can create <span> tags using the UI. Which is not actually true.

In fact, most people seem to be really annoyed by <span> in general — we used to be more pragmatic but got a lot of backlash. See #3273983: Do not assume that plugin supporting <tag attr> also supports <tag> in SourceEditingRedundantTags and upgrade path.

or would it be best to create a contrib module for this?

I think an ckeditor5_implicitly_allow_spans contrib module would make sense, yes!

Status: Fixed » Closed (fixed)

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