Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#10471 closed New Feature (duplicate)

CKEDITOR.filter rules aren't versatile enough in certain case. e.g.: allow all data attributes

Reported by: Daazku Owned by:
Priority: Normal Milestone:
Component: Core : Output Data Version: 4.0 Beta
Keywords: ACF Cc:

Description

As the title says there is some problem with the current implementation of CKEDITOR.filter.

It cannot allow all possible data attributes.

It would be great if I could type data-* (If we do it regex like it would be data-+ in that case) so that all data attributes matches.

This could even be extended to style or class as well. eg: background* would match background, background-color, background-position...

I put it as new features but it might be a "bug" because I actually have no way to allow all data attributes and it is painful to allow generic.

Change History (5)

comment:1 Changed 7 years ago by Daazku

Workaround for now:

editor.on('instanceReady', function(e) {
    //Get the filter object (ACF)
    var filter = e.editor.filter;
    
    //Bypass the allow function and create a rule directly
    if (!filter._.rules.generic) {
        filter._.rules.generic = [];
    }
    filter._.rules.generic.push({
        //Thanks to "optimizeRule", funtions are allowed
        attributes: function(attribute) {
            return /data-+/.test(attribute);
        },
        classes: false,
        elements: true,
        match: null,
        nothingRequired: false,
        propertiesOnly: true,
        requiredAttributes: [],
        requiredClasses: [],
        requiredStyles: [],
        styles: false
    });
});
Last edited 7 years ago by Daazku (previous) (diff)

comment:2 Changed 7 years ago by Piotrek Koszuliński

Keywords: data filter removed
Resolution: duplicate
Status: newclosed
Version: 4.1.14.0 Beta

This is an exact duplicate of #10202, which we will fortunately include in the next major release. There will be possible even more when using the object format, because full regexp format will be available.

The workaround for now could also be to use the match property of object format rule (an example can be found here: https://github.com/ckeditor/ckeditor-dev/blob/master/plugins/pagebreak/plugin.js#L129-L140), however your solution is more straightforward.

comment:3 in reply to:  2 Changed 7 years ago by Daazku

Replying to Reinmar:

This is an exact duplicate of #10202, which we will fortunately include in the next major release. There will be possible even more when using the object format, because full regexp format will be available.

The workaround for now could also be to use the match property of object format rule (an example can be found here: https://github.com/ckeditor/ckeditor-dev/blob/master/plugins/pagebreak/plugin.js#L129-L140), however your solution is more straightforward.

Sorry for the duplicate. Seems like I didn't search enough!

About match: Would it not only allows the element? From what I understood from the code you have no access to the status object so you cannot put the "data" attributes to be valid which will cause them to be stripped anyway.

If i'm not wrong, it may be useful to get a reference to the status object in the match function. However with the proposed fix in #10202 it may not be necessary.

Last edited 7 years ago by Daazku (previous) (diff)

comment:4 Changed 7 years ago by Piotrek Koszuliński

Sorry for the duplicate. Seems like I didn't search enough!

No problem. It's usually hard to find anything here ;).

About match: Would it not only allows the element? From what I understood from the code you have no access to the status object so you cannot put the "data" attributes to be valid which will cause them to be stripped anyway.

If i'm not wrong, it may be useful to get a reference to the status object in the match function. However with the proposed fix in #10202 it may not be necessary.

I'm surprised by how much you know about the filter :). I hope you liked its code.

Regarding match - it just allows to make a decision whether rule can be applied to a specific element. Nothing more. So, it could be used to partially solve your issue and in not very clear way.

I was also thinking whether it would be handy to give access to a status object from some rule's callback (match or... exec - dunno). It would be powerful, but at the same time, unless it has a good API, it would work in mysterious way :). Thus, I'm not planning to work on this before I have a real case.

comment:5 in reply to:  4 Changed 7 years ago by Daazku

Replying to Reinmar:

Sorry for the duplicate. Seems like I didn't search enough!

No problem. It's usually hard to find anything here ;).

About match: Would it not only allows the element? From what I understood from the code you have no access to the status object so you cannot put the "data" attributes to be valid which will cause them to be stripped anyway.

If i'm not wrong, it may be useful to get a reference to the status object in the match function. However with the proposed fix in #10202 it may not be necessary.

I'm surprised by how much you know about the filter :). I hope you liked its code.

I had to check the code to know what were my possibilities about matching data-* . Yeah I liked the code alot! Good comments and clever implementation!

Regarding match - it just allows to make a decision whether rule can be applied to a specific element. Nothing more. So, it could be used to partially solve your issue and in not very clear way.

I was also thinking whether it would be handy to give access to a status object from some rule's callback (match or... exec - dunno). It would be powerful, but at the same time, unless it has a good API, it would work in mysterious way :). Thus, I'm not planning to work on this before I have a real case.

Like I said it could be useful but not necessary at all for the moment!

Continue the good work!

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy