Is there a way to allow all html attributes for CKEditor5 or use a wildcard?
Asked Answered
J

1

6

I'm setting up ckeditor5, but it removes a lot of the html attributes. I want to know if there's a way to allow all attributes without specifying one by one, or maybe specify it with a wildcard.

(example)

editor.model.schema.extend('$block', { allowAttributes: 'on-*'}); //for onclick and other events

Here's the way I'm doing it so far, which is a bit tedious since I have to specify each attributes.

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';

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

        let allowedAttributes = [
            'id',
            'class'
        ];

        editor.model.schema.extend('$root', { allowAttributes: allowedAttributes });
        editor.model.schema.extend('$block', { allowAttributes: allowedAttributes });
        editor.model.schema.extend('$text', { allowAttributes: allowedAttributes });

        for (var i = 0; i < allowedAttributes.length; i++) {
            editor.conversion.attributeToAttribute({ model: allowedAttributes[i], view: allowedAttributes[i] });
        }

    }
}
Jerejereld answered 20/6, 2019 at 20:35 Comment(0)
C
1

CKEditor has a separate configuration to enable all HTML features. Adding that should resolve your issue.

https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support.html#enabling-all-html-features

htmlSupport: {
    allow: [
        {
            name: /.*/,
            attributes: true,
            classes: true,
            styles: true
        }
    ]
}
Companionway answered 20/7, 2022 at 4:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.