CKEDITOR.htmlParser.filterRulesDefinition
Abstract class describing the definition of CKEDITOR.htmlParser.filter rules.
Definition object represents rules as a set of properties with callback functions to be applied for transforming and filtering content upon data processing.
It can be used with CKEDITOR.htmlParser.filter and CKEDITOR.htmlParser.filter.addRules.
Filtering
Properties
-
attributeNames : nameTransformRule[]
CKEDITOR.htmlParser.filterRulesDefinition#attributeNames
An array of rules for attribute names transformation. Every matching string from the first item will be converted into the second.
Examples:
attributeNames: [ [ 'data-foo', 'data-bar' ], // Converts the string in the attribute name from 'data-foo' into 'data-bar'. // Note that the 'data-foo-baz' attribute will be converted into 'data-bar-baz'. [ /^data-custom$/, 'data-cke' ] // Converts the 'data-custom' attribute into 'data-cke'. ]
-
attributes : Object.<String, Function>
CKEDITOR.htmlParser.filterRulesDefinition#attributes
An object containing pairs of element attribute names and functions used upon attribute filtering and transformation.
Returning
false
removes the attribute.Examples:
attributes: { 'class': function( value, element ) { if ( element.name === 'div' ) { return value + ' cke_div' // Adds the 'cke_div' class to every filtered div element. } }, id: function() { return false; // Removes the 'id' attribute from every filtered element. } }
-
comment : Function
CKEDITOR.htmlParser.filterRulesDefinition#comment
Function for comments filtering and transforming. Returned value replaces comment text. If
false
is returned, the comment is removed.Examples:
comment: function( value, element ) { return false; // Removes the comment. }
-
elementNames : nameTransformRule[]
CKEDITOR.htmlParser.filterRulesDefinition#elementNames
An array of rules for element names transformation. Every rule match will be replaced by the given string.
Examples:
elementNames: [ [ /^div$/, 'p' ], // Converts 'div' into 'p'. [ /^cke:?/, '' ] // Removes 'cke:' prefixes. ]
-
elements : Object.<String, Function>
CKEDITOR.htmlParser.filterRulesDefinition#elements
An object containing pairs of element selectors and functions used upon element filtering and transformation.
A selector can be either an element name or one of the following:
^
,$
.^
and$
are to be applied on every filtered element. The first is applied before the element-specific filter, and the second is applied after the element-specific filter.The function can contain a return statement:
- If
false
is returned, the element is removed. - If another element is returned, it overwrites the original element.
Examples:
elements: { '^': function( element ) { // Element transformation to be applied on every filtered element. // This will be applied as the first filter. }, div: function( element ) { // Element transformation. }, p: function() { return false; // Removes each '<p>' element. }, '$': function( element ) { // Element transformation to be applied on every filtered element. // This will be applied after other defined filters. }, }
- If
-
root : Function
CKEDITOR.htmlParser.filterRulesDefinition#root
Function for root element transforming.
Examples:
root: function( element ) { element.children.push( someElement ); // Appends a child to the root element. }
-
text : Function
CKEDITOR.htmlParser.filterRulesDefinition#text
Function for text content transforming. Returned value replaces text.
Examples:
text: function( value, element ) { return value.toLowerCase(); // Transforms each text into lower case. }