Prevent inherited content color from being pasted#163
Open
SoftCreatR wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
CKEditor treats this as intentional
fontColorformatting and serializes it into stored content.Solution
Add a clipboard sanitizer in
WoltlabPasteFromOfficeduringClipboardPipeline#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:
Additional checks: