Ticket #3585: 3585_2.patch

File 3585_2.patch, 2.4 KB (added by Garry Yao, 15 years ago)
  • core/htmlparser/fragment.js

     
    7575                                                pendingName = pendingElement.name,
    7676                                                pendingDtd = CKEDITOR.dtd[ pendingName ],
    7777                                                currentDtd = currentNode.name && CKEDITOR.dtd[ currentNode.name ];
    78 
    79                                         if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) )
     78                                        // Check for any pending text nodes.
     79                                        if ( !pendingName )
    8080                                        {
     81                                                // Remove the pending first.
     82                                                pendingInline.splice( i, 1 );
     83                                                i--;
     84                                                if ( fixForBody && !currentNode.type )
     85                                                        this.onTagOpen( 'p', {} );
     86                                                currentNode.add(  pendingElement );
     87                                        }
     88                                        else if ( ( !currentDtd || currentDtd[ pendingName ] ) && ( !newTagName || !pendingDtd || pendingDtd[ newTagName ] || !CKEDITOR.dtd[ newTagName ] ) )
     89                                        {
    8190                                                // Get a clone for the pending element.
    8291                                                pendingElement = pendingElement.clone();
    8392
     
    196205                                }
    197206                        }
    198207
    199                         checkPending( tagName );
     208                        checkPending.call( this, tagName );
    200209
    201210                        element.parent = currentNode;
    202211                        element.returnPoint = returnPoint;
     
    210219
    211220                parser.onTagClose = function( tagName )
    212221                {
     222                        // Check for the last pending text node, rtrim the node value.
     223                        var lastPending = pendingInline[ pendingInline.length -1 ];
     224                        if ( lastPending && !lastPending.name )
     225                        {
     226                                var lastTextNode = pendingInline.pop(),
     227                                        textValue = CKEDITOR.tools.rtrim( lastTextNode.value );
     228                                if ( textValue.length )
     229                                     currentNode.add( new CKEDITOR.htmlParser.text( textValue ) );
     230                        }
     231
    213232                        var index = 0,
    214233                                pendingAdd = [],
    215234                                candidate = currentNode;
     
    281300                                        return;
    282301                        }
    283302
    284                         checkPending();
     303                        checkPending.call( this );
     304                        // We need remove the tail-spaces of an element,
     305                        // so pending the text for checking later.
     306                        var textNode = new CKEDITOR.htmlParser.text( text );
    285307
    286                         if ( fixForBody && !currentNode.type )
     308                        if ( currentNode.name )
     309                                pendingInline.push( textNode );
     310                        else
     311                        {
    287312                                this.onTagOpen( 'p', {} );
    288 
    289                         currentNode.add( new CKEDITOR.htmlParser.text( text ) );
     313                                currentNode.add( textNode );
     314                        }
    290315                };
    291316
    292317                parser.onCDATA = function( cdata )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy