X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=677d8f3cbdb58cb9397cd0d252f6a2d48a889d4d;hp=a460bba57ef742079d4cbb243195a1f562f79af8;hb=4e90e78dc97789709ee7404359a5517540c27553;hpb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5 diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index a460bba..677d8f3 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -80,6 +80,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var dtd = CKEDITOR.dtd; + // Define orders of table elements. + var tableOrder = [ 'caption', 'colgroup', 'col', 'thead', 'tfoot', 'tbody' ]; + // Find out the list of block-like tags that can contain
. var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ); for ( var i in blockLikeTags ) @@ -160,6 +163,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return element; }, + // The contents of table should be in correct order (#4809). + table : function( element ) + { + var children = element.children; + children.sort( function ( node1, node2 ) + { + return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ? + CKEDITOR.tools.indexOf( tableOrder, node1.name ) > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0; + } ); + }, + embed : function( element ) { var parent = element.parent; @@ -238,23 +252,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Remove all class names starting with "cke_". return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false; } - }, - - comment : function( contents ) - { - // If this is a comment for protected source. - if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker ) - { - // Remove the extra marker for real comments from it. - if ( contents.substr( protectedSourceMarker.length, 3 ) == '{C}' ) - contents = contents.substr( protectedSourceMarker.length + 3 ); - else - contents = contents.substr( protectedSourceMarker.length ); - - return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents ) ); - } - - return contents; } }; @@ -379,9 +376,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }); } - function protectSource( data, protectRegexes ) + function unprotectSource( html, editor ) + { + var store = editor._.dataStore; + + return html.replace( //g, function( match, data ) + { + return decodeURIComponent( data ); + }).replace( /\{cke_protected_(\d+)\}/g, function( match, id ) + { + return store && store[ id ] || ''; + }); + } + + function protectSource( data, editor ) { var protectedHtml = [], + protectRegexes = editor.config.protectedSource, + store = editor._.dataStore || ( editor._.dataStore = { id : 1 } ), tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g; var regexes = @@ -414,7 +426,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return protectedHtml[ id ]; } ); - return ''; + + // Avoid protecting over protected, e.g. /\{.*?\}/ + return ( /cke_temp(comment)?/ ).test( match ) ? match + : ''; }); } data = data.replace( tempRegex, function( $, isComment, id ) @@ -425,7 +440,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license '-->'; } ); - return data; + + // Different protection pattern is used for those that + // live in attributes to avoid from being HTML encoded. + return data.replace( /(['"]).*?\1/g, function ( match ) + { + return match.replace( //g, function( match, data ) + { + store[ store.id ] = decodeURIComponent( data ); + return '{cke_protected_'+ ( store.id++ ) + '}'; + }); + }); } CKEDITOR.plugins.add( 'htmldataprocessor', @@ -471,7 +496,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // The source data is already HTML, but we need to clean // it up and apply the filter. - data = protectSource( data, this.editor.config.protectedSource ); + data = protectSource( data, this.editor ); // Before anything, we must protect the URL attributes as the // browser may changing them when setting the innerHTML later in @@ -533,7 +558,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license fragment.writeHtml( writer, this.htmlFilter ); - return writer.getHtml( true ); + var data = writer.getHtml( true ); + + // Restore those non-HTML protected source. (#4475,#4880) + data = unprotectRealComments( data ); + data = unprotectSource( data, this.editor ); + + return data; } }; })();