zie1ony
zie1ony

Reputation: 1260

CKEditor doesn't allow to have nested <a> element in widget

I would like to have widget that can have <button><a></a></button> inside. Unfortunately CKE deletes <a></a>. How to overcome this?

This is the code:

CKEDITOR.plugins.add( 'interButton', {
    requires: 'widget',
    icons: 'interButton',
    init: function( editor ) {

        editor.widgets.add('interButton', {
            button: 'Add Button',

            template:
                '<button><a></a></button>',

            allowedContent:
                'button[*]{*}(*); a[*]{*}(*)',

            upcast: function( element ) {
                return element.name == 'button';
            }
        });

    }
});

Upvotes: 0

Views: 388

Answers (1)

Manticore
Manticore

Reputation: 1284

You can push certain elements to the protectedSource and CKE will obey.

example:

config.protectedSource.push(/<button[^>]*><a[^>]*><\/a><\/button>/g);

I haven't tested the above, but it should work.

Upvotes: 1

Related Questions