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

1 participant