X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fhtmlparser%2Felement.js;h=b1d55475058944873ef9b1de5517ca34fbe40ce1;hb=refs%2Ftags%2Fv3.6.2;hp=533262e9153d053de9bb3fd105fe0bf809d1d6c4;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/core/htmlparser/element.js b/_source/core/htmlparser/element.js index 533262e..b1d5547 100644 --- a/_source/core/htmlparser/element.js +++ b/_source/core/htmlparser/element.js @@ -34,7 +34,7 @@ CKEDITOR.htmlParser.element = function( name, attributes ) */ this.children = []; - var tagName = attributes[ 'data-cke-real-element-type' ] || name; + var tagName = attributes[ 'data-cke-real-element-type' ] || name || ''; // Reveal the real semantic of our internal custom tag name (#6639). var internalTag = tagName.match( /^cke:(.*)/ ); @@ -60,6 +60,61 @@ CKEDITOR.htmlParser.element = function( name, attributes ) }; }; +/** + * Object presentation of CSS style declaration text. + * @param {CKEDITOR.htmlParser.element|String} elementOrStyleText A html parser element or the inline style text. + */ +CKEDITOR.htmlParser.cssStyle = function() +{ + var styleText, + arg = arguments[ 0 ], + rules = {}; + + styleText = arg instanceof CKEDITOR.htmlParser.element ? arg.attributes.style : arg; + + // html-encoded quote might be introduced by 'font-family' + // from MS-Word which confused the following regexp. e.g. + //'font-family: "Lucida, Console"' + ( styleText || '' ) + .replace( /"/g, '"' ) + .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g, + function( match, name, value ) + { + name == 'font-family' && ( value = value.replace( /["']/g, '' ) ); + rules[ name.toLowerCase() ] = value; + }); + + return { + + rules : rules, + + /** + * Apply the styles onto the specified element or object. + * @param {CKEDITOR.htmlParser.element|CKEDITOR.dom.element|Object} obj + */ + populate : function( obj ) + { + var style = this.toString(); + if ( style ) + { + obj instanceof CKEDITOR.dom.element ? + obj.setAttribute( 'style', style ) : + obj instanceof CKEDITOR.htmlParser.element ? + obj.attributes.style = style : + obj.style = style; + } + }, + + toString : function() + { + var output = []; + for ( var i in rules ) + rules[ i ] && output.push( i, ':', rules[ i ], ';' ); + return output.join( '' ); + } + }; +}; + (function() { // Used to sort attribute entries in an array, where the first element of @@ -127,7 +182,7 @@ CKEDITOR.htmlParser.element = function( name, attributes ) { var writer = new CKEDITOR.htmlParser.basicWriter(); CKEDITOR.htmlParser.fragment.prototype.writeChildrenHtml.call( element, writer, filter ); - element.children = new CKEDITOR.htmlParser.fragment.fromHtml( writer.getHtml() ).children; + element.children = new CKEDITOR.htmlParser.fragment.fromHtml( writer.getHtml(), 0, element.clone() ).children; isChildrenFiltered = 1; } }; @@ -163,6 +218,10 @@ CKEDITOR.htmlParser.element = function( name, attributes ) // filter but not the children. if ( !writeName ) { + // Fix broken parent refs. + for ( var c = 0, length = this.children.length ; c < length ; c++ ) + this.children[ c ].parent = element.parent; + this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter ); return; }