How to configure CKEditor so it keeps data attributes instead of removing them?

后端 未结 1 1880
無奈伤痛
無奈伤痛 2021-01-17 20:27

I use CKeditor for editing rich HTML pages, but some javascript functionality relies on special attributes of the tags that triggers them.

Tho

相关标签:
1条回答
  • 2021-01-17 20:36

    I found it:

    The special configuration option:

                extraAllowedContent: '*[*]{*}(*)'
    

    did the trick.

    So the constructor I use is:

        $('.wysiwyg').ckeditor({
                toolbar : 'Basic',
                extraAllowedContent: '*[*]{*}(*)'
        });
    

    Note that it's the "EXTRA" allowed content option, so it does not overwrite the default.

    Update: It turns out that my special attribute had some & in it, and CKEditor was replacing them with the HTML entity &. I added these two options:

                entities: false,
                basicEntities: false,
    

    but they prevented that from happening in text nodes only, not inside attributes. Then I found this option:

                forceSimpleAmpersand: true
    

    and it worked. It'll be okay for now, but if eventually I have to put & as part of any value --the entity, not just the & (this is usually required in content sharing links)-- the editor will break them, changing them to plain &.

    0 讨论(0)
提交回复
热议问题