X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fhtmlparser%2Felement.js;h=b1d55475058944873ef9b1de5517ca34fbe40ce1;hp=84a452ef922348d2460c4308aed7afeade9c486f;hb=refs%2Ftags%2Fv3.6.1;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba diff --git a/_source/core/htmlparser/element.js b/_source/core/htmlparser/element.js index 84a452e..b1d5547 100644 --- a/_source/core/htmlparser/element.js +++ b/_source/core/htmlparser/element.js @@ -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 @@ -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; }