Skip to content

Prevent inherited content color from being pasted#163

Open
SoftCreatR wants to merge 1 commit into
WoltLab:6.2from
SoftCreatR:bugfix/normalize-colors
Open

Prevent inherited content color from being pasted#163
SoftCreatR wants to merge 1 commit into
WoltLab:6.2from
SoftCreatR:bugfix/normalize-colors

Conversation

@SoftCreatR

Copy link
Copy Markdown

Summary

Prevent normal inherited WSC text color from being persisted as explicit font color when users copy and paste formatted text.

Ref: https://www.woltlab.com/community/thread/318933-graue-texte

Problem

Browsers serialize rich clipboard HTML with computed styles. Copying normal text from WSC in dark mode can produce clipboard HTML like:

<span style="color: rgb(209, 210, 211); ...">Text</span>

CKEditor treats this as intentional fontColor formatting and serializes it into stored content.

Solution

Add a clipboard sanitizer in WoltlabPasteFromOffice during ClipboardPipeline#inputTransformation, before CKEditor upcasts pasted HTML into model attributes.

The sanitizer removes color styles that match WSC’s inherited content text color (--wcfContentText) and keeps other formatting intact.

This is deliberately conservative: arbitrary external colors are not stripped, because browser clipboard HTML does not reliably distinguish inherited page color from intentionally colored author content.

Testing

Browser reproduction in Chrome:

  • Copying normal WSC dark-mode text produced clipboard HTML with color: rgb(209, 210, 211).
  • Without the fix, pasting serialized as:
<p><span style="color:rgb(209,210,211);">Wer anderen eine Bratwurst brät, hat ein Bratwurst-Bratgerät.</span></p>
  • With the fix, pasting serialized as:
<p>Wer anderen eine Bratwurst brät, hat ein Bratwurst-Bratgerät.</p>

Additional checks:

  • Default light content color is stripped.
  • Custom --wcfContentText: rgb(85, 85, 85) is stripped.
  • Bold text remains bold while only the inherited color is removed.
  • Explicit external/non-WSC colors are preserved.

Hook into the clipboard input transformation before CKEditor converts pasted HTML into model content.

When browsers copy normal WSC text, they may serialize inherited --wcfContentText as an inline color style. CKEditor then treats that as an intentional font color and persists it in the submitted markup. Strip only color styles that match the current WSC content text color, while preserving other formatting such as bold text.

Arbitrary external colors are intentionally left untouched because browser clipboard HTML does not distinguish inherited page color from intentional author formatting.
@BurntimeX
BurntimeX requested a review from dtdesign July 6, 2026 09:52
@dtdesign

Copy link
Copy Markdown
Member

I like the general idea but there are a few issues with your approach:

  • Placing it inside the plugin for pasted content from office is an odd choice at best. These things should exist in a separate plugin because it has nothing to do with that.
  • Nested font styles are completely ignored and your sanitizer would cripple these. Consider a span that sets the color to and have another span inside with the default color. Stripping the color from the inner span now paints the text using the outer color. You must probe any parents to check for different colors being set.
  • #getInheritedTextColors() is a bit too broad because it also checks the body/html and you would be surprised what wild colors are sometimes being set there. I do not think checking for anything but the editor and the CSS variable is worth it, you just risk over-filtering.
  • #addStyleSheetTextColors() looks super costly with large sets of stylesheets, especially because this runs on every paste event right now. If you are concerned about the changes to the color scheme, you could try monitoring the html[data-color-scheme] attribute for changes.
  • Speaking of the color scheme, this is currently not handled at all. In theory the source of the pasted text could be the same exact page but with a different color scheme due to automated day/night cycle switches. Debatabale how much of an issue this really is but worth considering imo.

@dtdesign dtdesign left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants