|
104 | 104 | this.applyTo( evt.data.dataValue, true );
|
105 | 105 | }, this, null, 6 );
|
106 | 106 |
|
107 |
| - // Filter outcoming "data". |
108 |
| - // Add element filter after htmlDataProcessor.htmlFilter |
| 107 | + // Transform outcoming "data". |
| 108 | + // Add element filter after htmlDataProcessor.htmlFilter |
109 | 109 | // when preparing output data HTML.
|
110 | 110 | this._.toDataFormatListener = editor.on( 'toDataFormat', function( evt ) {
|
111 |
| - this.applyTo( evt.data.dataValue ); |
| 111 | + this.applyTo( evt.data.dataValue, false, true ); |
112 | 112 | }, this, null, 11 );
|
113 | 113 | }
|
114 | 114 | // Rules object passed in editorOrRules argument - initialize standalone filter.
|
|
192 | 192 | * of filtering is DOM tree without disallowed content.
|
193 | 193 | *
|
194 | 194 | * @param {CKEDITOR.htmlParser.fragment/CKEDITOR.htmlParser.element} fragment Node to be filtered.
|
195 |
| - * @param {Boolean} toHtml Set to `true` if filter is used together with {@link CKEDITOR.htmlDataProcessor#toHtml}. |
| 195 | + * @param {Boolean} [toHtml] Set to `true` if filter is used together with {@link CKEDITOR.htmlDataProcessor#toHtml}. |
| 196 | + * @param {Boolean} [transformOnly] If set to `true` only transformations will be applied. Content |
| 197 | + * won't be filtered with allowed content rules. |
196 | 198 | */
|
197 |
| - applyTo: function( fragment, toHtml ) { |
| 199 | + applyTo: function( fragment, toHtml, transformOnly ) { |
198 | 200 | var toBeRemoved = [],
|
199 |
| - rules = this._.rules, |
| 201 | + rules = !transformOnly && this._.rules, |
200 | 202 | transformations = this._.transformations,
|
201 | 203 | filterFn = getFilterFunction( this ),
|
202 | 204 | protectedRegexs = this.editor && this.editor.config.protectedSource;
|
|
717 | 719 |
|
718 | 720 | // Return and cache created function.
|
719 | 721 | // @param {CKEDITOR.htmlParser.element}
|
720 |
| - // @param optimizedRules Rules to be used. |
| 722 | + // @param [optimizedRules] Rules to be used. |
721 | 723 | // @param [transformations] Transformations to be applied.
|
722 | 724 | // @param {Array} toBeRemoved Array into which elements rejected by the filter will be pushed.
|
723 | 725 | // @param {Boolean} [toHtml] Set to true if filter used together with htmlDP#toHtml
|
|
739 | 741 |
|
740 | 742 | for ( i = 0; i < transformations.length; ++i )
|
741 | 743 | applyTransformationsGroup( that, element, transformations[ i ] );
|
742 |
| - } |
743 |
| - |
744 |
| - // Name could be changed by transformations. |
745 |
| - name = element.name; |
746 |
| - |
747 |
| - var rules = optimizedRules.elements[ name ], |
748 |
| - genericRules = optimizedRules.generic, |
749 |
| - status = { |
750 |
| - // Whether any of rules accepted element. |
751 |
| - // If not - it will be stripped. |
752 |
| - valid: false, |
753 |
| - // Objects containing accepted attributes, classes and styles. |
754 |
| - validAttributes: {}, |
755 |
| - validClasses: {}, |
756 |
| - validStyles: {}, |
757 |
| - // Whether all are valid. |
758 |
| - // If we know that all element's attrs/classes/styles are valid |
759 |
| - // we can skip their validation, to improve performance. |
760 |
| - allAttributes: false, |
761 |
| - allClasses: false, |
762 |
| - allStyles: false |
763 |
| - }; |
764 | 744 |
|
765 |
| - // Early return - if there are no rules for this element (specific or generic), remove it. |
766 |
| - if ( !rules && !genericRules ) { |
767 |
| - toBeRemoved.push( element ); |
768 |
| - return; |
| 745 | + // Update style and class attrs, because that won't be done after applying rules. |
| 746 | + if ( !optimizedRules ) |
| 747 | + updateAttributes( element ); |
769 | 748 | }
|
770 | 749 |
|
771 |
| - // Could not be done yet if there were no transformations and if this |
772 |
| - // is real (not mocked) object. |
773 |
| - populateProperties( element ); |
| 750 | + if ( optimizedRules ) { |
| 751 | + // Name could be changed by transformations. |
| 752 | + name = element.name; |
| 753 | + |
| 754 | + var rules = optimizedRules.elements[ name ], |
| 755 | + genericRules = optimizedRules.generic, |
| 756 | + status = { |
| 757 | + // Whether any of rules accepted element. |
| 758 | + // If not - it will be stripped. |
| 759 | + valid: false, |
| 760 | + // Objects containing accepted attributes, classes and styles. |
| 761 | + validAttributes: {}, |
| 762 | + validClasses: {}, |
| 763 | + validStyles: {}, |
| 764 | + // Whether all are valid. |
| 765 | + // If we know that all element's attrs/classes/styles are valid |
| 766 | + // we can skip their validation, to improve performance. |
| 767 | + allAttributes: false, |
| 768 | + allClasses: false, |
| 769 | + allStyles: false |
| 770 | + }; |
| 771 | + |
| 772 | + // Early return - if there are no rules for this element (specific or generic), remove it. |
| 773 | + if ( !rules && !genericRules ) { |
| 774 | + toBeRemoved.push( element ); |
| 775 | + return; |
| 776 | + } |
774 | 777 |
|
775 |
| - if ( rules ) { |
776 |
| - for ( i = 0, l = rules.length; i < l; ++i ) |
777 |
| - applyRule( rules[ i ], element, status, true, skipRequired ); |
778 |
| - } |
| 778 | + // Could not be done yet if there were no transformations and if this |
| 779 | + // is real (not mocked) object. |
| 780 | + populateProperties( element ); |
779 | 781 |
|
780 |
| - if ( genericRules ) { |
781 |
| - for ( i = 0, l = genericRules.length; i < l; ++i ) |
782 |
| - applyRule( genericRules[ i ], element, status, false, skipRequired ); |
783 |
| - } |
| 782 | + if ( rules ) { |
| 783 | + for ( i = 0, l = rules.length; i < l; ++i ) |
| 784 | + applyRule( rules[ i ], element, status, true, skipRequired ); |
| 785 | + } |
784 | 786 |
|
785 |
| - // Finally, if after running all filter rules it still hasn't been allowed - remove it. |
786 |
| - if ( !status.valid ) { |
787 |
| - toBeRemoved.push( element ); |
788 |
| - return; |
789 |
| - } |
| 787 | + if ( genericRules ) { |
| 788 | + for ( i = 0, l = genericRules.length; i < l; ++i ) |
| 789 | + applyRule( genericRules[ i ], element, status, false, skipRequired ); |
| 790 | + } |
790 | 791 |
|
791 |
| - // Update element's attributes based on status of filtering. |
792 |
| - updateElement( element, status ); |
| 792 | + // Finally, if after running all filter rules it still hasn't been allowed - remove it. |
| 793 | + if ( !status.valid ) { |
| 794 | + toBeRemoved.push( element ); |
| 795 | + return; |
| 796 | + } |
793 | 797 |
|
794 |
| - if ( !skipFinalValidation && !validateElement( element ) ) { |
795 |
| - toBeRemoved.push( element ); |
796 |
| - return; |
| 798 | + // Update element's attributes based on status of filtering. |
| 799 | + updateElement( element, status ); |
| 800 | + |
| 801 | + if ( !skipFinalValidation && !validateElement( element ) ) { |
| 802 | + toBeRemoved.push( element ); |
| 803 | + return; |
| 804 | + } |
797 | 805 | }
|
798 | 806 |
|
799 | 807 | // Protect previously unprotected elements.
|
|
0 commit comments