Log in or register to post comments
Last post
htmlFilter executes but doesn't get applied for insertHtml
I've got a plugin using an htmlFilter.

When I add the image tag using editor.document.getBody().appendHtml("<img src='mysrc'>"), when switching to source mode the filter gets applied and replaces the src attribute of the image element. I can see this change in the source view.

However, if I use editor.insertHtml("<img src='mysrc'>"), when switching to source mode, I still hit the breakpoint and overwrite the element.attributes.src value but the source view does not show the src attribute as changed.

How is it that an element added with editor.insertHtml will not apply a change made to element.attributes.src when switching to Source mode?

afterInit: function(editor)
                        var htmlFilter = dataProcessor && dataProcessor.htmlFilter;

         if ( htmlFilter )
         {            
            htmlFilter.addRules(
            {
               elements:
               {
                  img : function(element)
                  {

                     var pattern = new RegExp("mysrc", "i");
                     if ( pattern.test(element.attributes.src) )
                     {
                        element.attributes.src = replaceSrc(pattern, element.attributes.src);
                     }
                  }
               }
            });
         }

Re: htmlFilter executes but doesn't get applied for insertHt
I also want to point out this simple htmlFilter also doesn't work if I manually write the html into source mode and give it a src attribute of "test" and switch to wysiwyg and back to source. The result is that src will remain "test" instead of changing to "An Image". If create an image tag with no src attribute, it will be updated to 'An Image'

editor.dataProcessor.htmlFilter.addRules(
         {
            elements :
            {
               img : function( element )
               {
                  element.attributes.src = 'An image';
               }
            }
         });
Re: htmlFilter executes but doesn't get applied for insertHt
I found the solution was that I needed to also set this attribute in addition to element.attributes.src:
element.attributes['data-cke-saved-src']