How to configure CKEditor to save data attributes instead of deleting them?

I use CKeditor to edit rich HTML pages, but some javascript functions depend on the special attributes of the tags <a>that trigger them.

These are rare cases, only a few records in the database of 5000+ records should run this function, and this particular js-module needs special attributes as a parameterization parameter:

<a href="#" data-from="ROM" data-to="NYC" data-promo="8373794">Buy your tickets</a>

CKeditor allows me to add these attributes (by editing the source code of the post), but when the client edits the page, the editor removes them and violates this functionality.

To instruct my client not to edit this particular entry seems unprofessional. Switching to another WYSIWYG editor may work, but I see this as a last resort.

CKEditor must have a solution for this!

+4
source share
1 answer

I found him:

Special configuration option:

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

did the trick.

So I use the constructor:

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

Please note that the "EXTRA" option is enabled for content, so it does not overwrite the default value.

Update. It turns out that my special attribute had some in it, and CKEditor replaced them with an HTML object &amp;. I added these two options:

            entities: false,
            basicEntities: false,

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

            forceSimpleAmpersand: true

. , &amp; - , ( ) - , .

+6

Source: https://habr.com/ru/post/1531666/


All Articles