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

How to add onmouseover attributes to links using automatic decorators in CKEditor 5 (v36.0.1)? #17129

Open
datadevmobiledev opened this issue Sep 19, 2024 · 1 comment
Labels
domain:framework-dx This issue reports a problem with the developer experience while working with the framework. package:link type:question This issue asks a question (how to...).

Comments

@datadevmobiledev
Copy link

Hello,

I am using CKEditor 5 version 36.0.1 because it is the last version compatible with Node 14.

My goal is to add onmouseover events to links during editing. I am using the automatic decorator configuration, but I keep encountering the error: domconverter-unsafe-attribute-detected.

The onmouseover attribute is being renamed to data-ck-unsafe-attribute-onmouseover.

I read about renderUnsafeAttributes in the documentation, but I am unsure how to apply this setting with automatic decorators.

Questions:

  • Is it possible to add the onmouseover attribute to links through automatic decorators?
  • How can I use renderUnsafeAttributes with automatic decorators?

I attempted to create a plugin with the following code, but it didn't resolve the issue:

export default class AllowInteractiveAttributes extends Plugin {
    init() {
        const editor = this.editor;

        editor.model.schema.extend( '$text', { allowAttributes: [ 'onclick', 'onmouseover' ] } );

        editor.conversion.for( 'downcast' ).attributeToElement( {
            model: 'Text',
            view: ( modelAttributeValue, viewWriter ) => {
                return viewWriter.createAttributeElement('a', { onclick: modelAttributeValue }, { renderUnsafeAttributes: ['onclick'] });
            },
            converterPriority: 'high',
        });
    }
}

Context:

The goal is to use automatic decorators to add custom event handlers (e.g., onmouseover) to links during the editing process, but these attributes are being renamed due to security policies (domconverter-unsafe-attribute-detected). I would like to understand the proper way to bypass this behavior for specific attributes.

Any help or guidance would be greatly appreciated!

Thank you!

@datadevmobiledev datadevmobiledev added the type:question This issue asks a question (how to...). label Sep 19, 2024
@skydogtk
Copy link

I am interested in the answer to this question.

@Witoso Witoso added domain:framework-dx This issue reports a problem with the developer experience while working with the framework. package:link labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:framework-dx This issue reports a problem with the developer experience while working with the framework. package:link type:question This issue asks a question (how to...).
Projects
None yet
Development

No branches or pull requests

3 participants