Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add htmlNormalization event to ClipboardPipeline. #17696

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Mati365
Copy link
Member

@Mati365 Mati365 commented Dec 27, 2024

Suggested merge commit message (convention)

Feature (clipboard): It's now possible to attach custom HTML serialize functions to clipboard pipeline, just before processing it into view fragment. Closes #17309
Internal (paste-from-office): Use inputHtmlNormalization clipboard event to handle HTML normalization.


Additional information

The ClipboardPipeline is performing some HTML normalization (on string) just before converting it to the view document fragment:

if ( dataTransfer.getData( 'text/html' ) ) {
contentData = normalizeClipboardHtml( dataTransfer.getData( 'text/html' ) );
} else if ( dataTransfer.getData( 'text/plain' ) ) {
contentData = plainTextToHtml( dataTransfer.getData( 'text/plain' ) );
}

~Kuba


⚠️ I'm not pretty sure if this flag is still needed: 79555ac#diff-4b980c1afbffe5148af9316676ffda4ac77a98664dc69fcf7c07ba7726d3c42cR47. It's not fully documented so I kept it in evt.return property.

@Mati365 Mati365 requested review from niegowski and arkflpc December 27, 2024 11:54
Comment on lines +227 to +236
const htmlOrView = this.fire<ClipboardInputHTMLNormalizationEvent>( 'inputHtmlNormalization', {
html: dataTransfer.getData( 'text/html' ),
dataTransfer,
method: data.method
} ) || '';

if ( typeof htmlOrView === 'string' ) {
content = this.editor.data.htmlProcessor.toView( htmlOrView );
} else {
content = htmlOrView;
Copy link
Contributor

Choose a reason for hiding this comment

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

The ClipboardPipeline is a linear sequence of events (as described at the top of this file). This change would make it inconsistent as it would be a side quest. I suggest extracting the clipboardInput firing code from the ClipboardObserver to the corresponding pipelines (clipboard pipeline and dragdrop). Then the normalization could be implemented in the listener for the paste (and drop) event listener and the sequence of events would not be broken. Especially that copy and cut are implemented locally in the pipeline, not in the observer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants