Problem/Motivation

The Remove Format button does not remove inline styles. When I have some text that contains inline styles, I select/highlight some text in the editor but the Remove Format button remains gray/inactive, and clicking it does nothing; formatting is not stripped. For example paragraph and span tags with some inline styles, and those inline styles don't get removed. There are no JavaScript errors in the console, either in Chrome or Firefox.

Steps to reproduce

Select some text in the editor and click the Remove Format button.

Proposed resolution

https://github.com/ckeditor/ckeditor5/issues/13983

Remaining tasks

No idea

User interface changes

None

API changes

On https://ckeditor.com/docs/ckeditor5/latest/features/remove-format.html I see there's a Ckeditor5 API for extending the Remove Format plugin to allow removing specific elements using the isFormatting property, but I think this is not needed here; somehow it seems the default Remove Format functionality isn't working, at least not for me.

Data model changes

No idea

Release notes snippet

N/A

Comments

caspervoogt created an issue. See original summary.

caspervoogt’s picture

Issue summary: View changes
StatusFileSize
new14.81 KB
new5.6 KB
wim leers’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce, +Needs tests

Thanks for taking the time to report this!

Can you please provide exact steps to reproduce? That means the CKEditor 5 configuration (export the editor and filter_format config entities please) as well as the sample HTML you're testing this with.

caspervoogt’s picture

Issue summary: View changes
caspervoogt’s picture

StatusFileSize
new498 bytes
new141 bytes

I attached config exports. Also, here's a ~2 min screencast showing the issue.

I did not allow the style attribute (I don't think I need to?!); I am able to add it into my source HTML and save it, though. Yet CKeditor5 won't strip it with Remove Formatting. I am also not using any filters.

Essentially, inline styles don't get stripped, whereas in CKeditor 4 they did (as far as I can recall). Manually removing inline styles can be a pain.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce

Thanks, @caspervoogt!

nod_’s picture

Category: Bug report » Support request
Status: Active » Needs review
Issue tags: -Needs tests

Seems like a feature, not a bug.

Per CKE5 documentation : "Note that block-level formatting (headings, images) and semantic data (links) will not be removed by this feature." the p tag is block-level so it makes sense it will not remove the style as documented.

wim leers’s picture

Title: Remove Format button does nothing » Remove Format button does not remove `style` attribute

Would this be a better description then?

nod_’s picture

Title: Remove Format button does not remove `style` attribute » Remove Format button does not remove `style` attribute on block level element
caspervoogt’s picture

In my case neither block nor inline styles get removed.

I take another look at my test case in this brief video.

No style attributes get removed from either paragraph or span elements. I *can* format <b>, <strong>, <i>, <em>, <u>, but only if those buttons are present in the editor; adding one of those elements AND having their button present in the editor is the only only way I can get the Remove Button to activate, but it still doesn't remove style attributes / inline styles.

caspervoogt’s picture

Title: Remove Format button does not remove `style` attribute on block level element » Remove Format button does not remove `style` attributes
caspervoogt’s picture

Issue summary: View changes
caspervoogt’s picture

Issue summary: View changes

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.

Moving to NW as there still appears to be more discussion vs anything to actually review from what I can tell. Maybe we need to expand the functionality of the remove formatter button (if that's possible)

wim leers’s picture

Status: Needs work » Active

It was marked as needing review in #7, but there's no actual patch yet. So … moving to Active.

caspervoogt’s picture

Thanks for the update, smustgrave and Wim. I think this is likely more an issue with Ckeditor itself and not Drupal, judging by the issues at https://github.com/ckeditor/ckeditor5/issues/11574, but I can't say for sure. I'm not the only one running into these issues, based on some of the the threads there.

smustgrave’s picture

Will admit its very confusing to have a remove formatting button that doesn’t actually remove all formatting. Couldn’t imagine having to explain that to a client..

wim leers’s picture

Title: Remove Format button does not remove `style` attributes » [upstream] Remove Format button does not remove `style` attributes
Category: Support request » Bug report
Priority: Normal » Major
Status: Active » Postponed
Issue tags: +Usability, +Needs upstream bugfix
mohithasmukh’s picture

Hi there,

I am also facing the same issue, when the content editors go in to remove the formatting the inline styles are not removed. Has anyone found any workaround this?

Thank you.

aaronbauman’s picture

The workaround we're advising clients is to use the "paste as plain text" button, or cmd-shift-v

caspervoogt’s picture

This apparently just got fixed on the ckeditor5 master branch. See https://github.com/ckeditor/ckeditor5/pull/13949.

wim leers’s picture

Wonderful! Looks like many Style-related bugs are being fixed in the current development cycle: https://github.com/ckeditor/ckeditor5/milestone/67?closed=1.

… but it did not yet ship in CKEditor 37.1.0, which we just updated to yesterday: #3355358: Update CKEditor 5 to 37.1.0.

So it looks like this will be for either 37.2.0 or 38.x. Still, great news! 😊

witeksocha’s picture

Just keep in mind we improved the Remove format for inline, as it was the fastest :) The Remove format for blocks will be tracked here: https://github.com/ckeditor/ckeditor5/issues/13983

wim leers’s picture

Thanks for that clarification! 😊

caspervoogt’s picture

Witek beat me here.. I was going to post the same thing. Very happy to see this progressing.

sachbearbeiter’s picture

Top :)
And thankful ...

wim leers’s picture

Version: 9.5.x-dev » 11.x-dev

Still tracking for https://github.com/ckeditor/ckeditor5/issues/13983 — updating target version.

caspervoogt’s picture

https://github.com/ckeditor/ckeditor5/issues/13983 has only 7 votes; maybe if some more Drupal folks can log into Github and upvote it, the CKEditor maintainers will give it higher priority :)

montogro’s picture

Doesn't work for me either. Even somehow pasting as plain text with right click didn't solve this problem for text copied directly from word which is using its own fonts and styles.

Update: looks like it was text's issue itself, once I pasted it even notepad couldn't bring it back to plain text, but leaving empty squares only. Everything seems to be fine now.

eduardo morales alberti’s picture

As Wim Leers says in the comment https://www.drupal.org/project/drupal/issues/3321254#comment-15025068 it was fixed on https://github.com/ckeditor/ckeditor5/releases/tag/v38.0.0 but Drupal 9.5.x require "ckeditor5": "~35.4.0", on 11.x "ckeditor5": and 10.x seems that is required "~39.0.1".

mohithasmukh’s picture

Hi all,

I am confused but what is the workaround for websites that are still on 9.5 core?

Thanks.

eduardo morales alberti’s picture

@mohithasmukh There are no workarounds (or I did not find any at least), the solution is to keep CKEditor 4 until update Drupal to version 10 and then use CKEditor 5, the 9.5 support ends in November.

wim leers’s picture

Issue summary: View changes

#31: #3321254: [upstream] Remove Format button does not remove `style` attributes from block-level elements is referring to the Style plugin and the Remove Format button working with that.

This issue is about the Remove Format button removing style attributes. That's a very different problem space.

https://github.com/ckeditor/ckeditor5/issues/13983 is the blocker, and it now has 28 votes already.

wim leers’s picture

Title: [upstream] Remove Format button does not remove `style` attributes » [upstream] Remove Format button does not remove `style` attributes from block-level elements

Reported once more, now by @igorbarato, at https://drupal.slack.com/archives/C01GWN3QYJD/p1695231744469799.

Clarifying issue title.

aasarava’s picture

Unfortunately, the fix to remove inline formatting still excludes classes/styles on links. I've opened a followup issue:
https://github.com/ckeditor/ckeditor5/issues/15318

wim leers’s picture

Thanks, @aasarava!

hephaestus’s picture

As it doesn't look like this is going to be implemented upstream in the near future, is anyone aware of a workaround to force this behaviour, if you're happy to take a scorched earth approach to attributes on elements?

We've got clients trying to paste in a lot of documents from Word, and the "remove formatting" button only stripping styles from inline elements tends to leave the document with a broken mix of styling, mostly relating to sizing and spacing. Stripping styles after the fact in the filter prevents intentional styling and makes the editing experience very inconsistent when they're still visible within the editor.

scott_euser’s picture

We have been using the 'CK editor 5 Paste Filter' module as a temp fix to catch things on paste. Not quite the same so might not work for you.

hephaestus’s picture

Thanks Scott, that does solve our immediate issue.

caspervoogt’s picture

Good news!

https://github.com/ckeditor/ckeditor5/issues/15318 was just merged into the CKEditor master branch. Here's the relevant PR; https://github.com/ckeditor/ckeditor5/pull/18603, which resolves a number of 'remove format' issues.

Next I suppose core/modules/ckeditor5/ckeditor5.libraries.yml and core/assets/vendor/ckeditor5 should be updated to use the latest ckeditor5 library.

jackfoust’s picture

Would love to see this roll out to 10.5 and 11.2, but I'm guessing there may be some hesitation with the still prevalent issues when we started using CKEditor 45.2.0?

ken hawkins’s picture

This one has been a recurrent thorn in our side since leaving CKEditor 4 and I've yet to find an existing fix in Drupal.

I believe we're waiting on v46.0.0 to make its way to Drupal https://github.com/ckeditor/ckeditor5/releases/tag/v46.0.0 as it has the revised clear formatting PR mentioned at https://www.drupal.org/project/drupal/issues/3321254#comment-16136275 (https://ckeditor.com/docs/ckeditor5/latest/features/remove-format.html)

- 10.5.x and 11.2.x are still on 45.2.2: https://git.drupalcode.org/project/drupal/-/blob/10.5.x/core/package.jso...
- 10.6.x ann 11.4.x should move to 47.0.0: https://git.drupalcode.org/project/drupal/-/blob/10.6.x/core/package.jso...

Using simplytestme for 10.6.x it appears this is a change of behaviour for the remove formatting button. <= v45 = clear CKeditor styles, >= v46 clear all styles.

(aside: I imagine some editors will be taken off guard by the change).

Before I realize the above, I made a small workaround module that others may find helpful: https://github.com/khawkins98/ckeditor_clean_styles

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

ken hawkins’s picture

Status: Postponed » Closed (outdated)

Verified that this is now working as expected in D10.6 (see earlier comment). Hurrah!

Being bold and closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

andrew.wang’s picture

Status: Closed (outdated) » Fixed

Marking this issue as fixed in #3340578: [meta] [upstream] Prioritized CKEditor 5 upstream blockers!
PS: @ken hawkins I think you meant 46.0.0 in #44 😛

Status: Fixed » Closed (fixed)

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