CKEditor不允许嵌套<a> element in widget

时间:2016-08-01 21:10:30

标签: ckeditor

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';
            }
        });

    }
});

1 个答案:

答案 0 :(得分:1)

您可以将某些元素推送到protectedSource,CKE也会遵守。

示例:

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

我还没有对上述内容进行测试,但它应该可行。