Ticket #2886: 2886_2.patch

File 2886_2.patch, 9.0 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/core/htmlparser/element.js

     
    5050        /** @private */
    5151        this._ =
    5252        {
    53                 isBlockLike : isBlockLike,
    54                 hasInlineStarted : isEmpty || !isBlockLike
     53                isBlockLike : isBlockLike
    5554        };
    5655};
    5756
  • _source/core/htmlparser/fragment.js

     
    3030        /** @private */
    3131        this._ =
    3232        {
    33                 isBlockLike : true,
    34                 hasInlineStarted : false
     33                isBlockLike : true
    3534        };
    3635};
    3736
     
    5655                        html = [],
    5756                        fragment = new CKEDITOR.htmlParser.fragment(),
    5857                        pendingInline = [],
     58                        isBrPending, isBrOptional,
     59                        isPre,
     60                        hasInlineContent,
    5961                        currentNode = fragment;
    6062
    6163                var checkPending = function( newTagName )
    6264                {
     65                        if ( isBrPending )
     66                        {
     67                                if ( !newTagName || CKEDITOR.dtd.$empty[ newTagName ] || newTagName == 'br' )
     68                                        currentNode.add( new CKEDITOR.htmlParser.element( 'br', {} ) );
     69                                isBrPending = false;
     70                        }
     71
    6372                        if ( pendingInline.length > 0 )
    6473                        {
    6574                                for ( var i = 0 ; i < pendingInline.length ; i++ )
     
    7483                                                // Get a clone for the pending element.
    7584                                                pendingElement = pendingElement.clone();
    7685
     86                                                if ( hasInlineContent )
     87                                                        hasInlineContent = !pendingElement._.isBlockLike && pendingElement.name != 'br';
     88
    7789                                                // Add it to the current node and make it the current,
    7890                                                // so the new element will be added inside of it.
    7991                                                currentNode.add( pendingElement );
     
    90102
    91103                parser.onTagOpen = function( tagName, attributes, selfClosing )
    92104                {
     105                        if ( tagName == 'br' )
     106                        {
     107                                if ( isPre )
     108                                {
     109                                        currentNode.add( new CKEDITOR.htmlParser.text( '\n', true ) );
     110                                        return;
     111                                }
     112                                else if ( isBrOptional )
     113                                {
     114                                        isBrPending = true;
     115                                        isBrOptional = false;
     116                                        return;
     117                                }
     118                        }
     119                        else if ( tagName == 'pre' )
     120                                isPre = true;
     121
    93122                        var element = new CKEDITOR.htmlParser.element( tagName, attributes );
    94123
    95124                        // "isEmpty" will be always "false" for unknown elements, so we
     
    104133                                return;
    105134                        }
    106135
     136                        if ( element.isEmpty )
     137                                isBrOptional = true;
     138
    107139                        var currentName = currentNode.name,
    108140                                currentDtd = ( currentName && CKEDITOR.dtd[ currentName ] ) || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span );
    109141
     
    133165                                                // and try adding the new one after it.
    134166                                                pendingInline.unshift( currentNode );
    135167                                        }
     168                                        else if ( isBrPending )
     169                                                isBrPending = !currentNode._.isBlockLike;
    136170
    137171                                        reApply = true;
    138172                                }
     
    152186
    153187                        currentNode.add( element );
    154188
     189                        if ( hasInlineContent )
     190                                hasInlineContent = !element._.isBlockLike && element.name != 'br';
     191
    155192                        if ( !element.isEmpty )
    156193                                currentNode = element;
    157194                };
     
    161198                        var closingElement = currentNode,
    162199                                index = 0;
    163200
     201                        if ( tagName == 'pre' )
     202                                isPre = false;
     203
    164204                        while ( closingElement && closingElement.name != tagName )
    165205                        {
    166206                                // If this is an inline element, add it to the pending list, so
     
    178218                        }
    179219
    180220                        if ( closingElement )
     221                        {
     222                                if ( isBrPending )
     223                                        isBrPending = !closingElement._.isBlockLike;
     224
    181225                                currentNode = closingElement.parent;
     226                        }
    182227                        else if ( pendingInline.length > index )
    183228                        {
    184229                                // If we didn't find any parent to be closed, let's check the
     
    199244
    200245                parser.onText = function( text )
    201246                {
    202                         if ( !currentNode._.hasInlineStarted )
     247                        if ( !hasInlineContent && !isPre )
    203248                        {
    204249                                text = CKEDITOR.tools.ltrim( text );
    205250
     
    208253                        }
    209254
    210255                        checkPending();
    211                         currentNode.add( new CKEDITOR.htmlParser.text( text ) );
     256                        currentNode.add( new CKEDITOR.htmlParser.text( text, isPre ) );
     257
     258                        isBrOptional = true;
    212259                };
    213260
    214261                parser.onComment = function( comment )
     
    261308                        node.parent = this;
    262309
    263310                        this.children.push( node );
    264 
    265                         this._.hasInlineStarted = node.type == CKEDITOR.NODE_TEXT || ( node.type == CKEDITOR.NODE_ELEMENT && !node._.isBlockLike );
    266311                },
    267312
    268313                /**
  • _source/core/htmlparser/text.js

     
    1212         * @constructor
    1313         * @example
    1414         */
    15         CKEDITOR.htmlParser.text = function( value )
     15        CKEDITOR.htmlParser.text = function( value, noSpacesFix )
    1616        {
    1717                /**
    1818                 * The text value.
    1919                 * @type String
    2020                 * @example
    2121                 */
    22                 this.value = value.replace( spacesRegex, ' ' );
     22                this.value = noSpacesFix ? value : value.replace( spacesRegex, ' ' );
    2323
    2424                /** @private */
    2525                this._ =
  • _source/plugins/htmlwriter/plugin.js

     
    5353                output : [],
    5454                indent : false,
    5555                indentation : '',
    56                 rules : {}
     56                rules : {},
     57                cdata : 0
    5758        };
    5859
    5960        var dtd = CKEDITOR.dtd;
     
    6263        {
    6364                this.setRules( e,
    6465                        {
    65                                 indent : true,
     66                                indent : ( e != 'pre' ),
    6667                                breakBeforeOpen : true,
    6768                                breakAfterOpen : true,
    6869                                breakBeforeClose : !dtd[ e ][ '#' ],
     
    101102                }
    102103
    103104                this._.output.push( '<', tagName );
     105               
     106                if ( tagName == 'pre' )
     107                        this._.cdata++;
    104108        },
    105109
    106110        /**
     
    174178
    175179                if ( rules && rules.breakAfterClose )
    176180                        this.lineBreak();
     181
     182                if ( tagName == 'pre' )
     183                        this._.cdata--;
    177184        },
    178185
    179186        /**
     
    185192         */
    186193        text : function( text )
    187194        {
    188                 if ( this._.indent )
     195                if ( this._.indent && !this._.cdata )
    189196                {
    190197                        this.indentation();
    191198                        text = CKEDITOR.tools.ltrim( text );
  • _source/tests/plugins/htmldataprocessor/htmldataprocessor.html

     
    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    22<html xmlns="http://www.w3.org/1999/xhtml">
    33<head>
    44        <title>Plugin: htmldataprocessor</title>
     
    7979                        assert.areSame( '<x:x><p>Test</p></x:x>', getDataProcessor().toDataFormat( element ) );
    8080                },
    8181
     82                test_toDataFormat_4 : function()
     83                {
     84                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p><br></p></div>' );
     85
     86                        assert.areSame( '<p><br /></p>', getDataProcessor().toDataFormat( element ) );
     87                },
     88
     89                test_toDataFormat_5 : function()
     90                {
     91                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p><br>A</p></div>' );
     92
     93                        assert.areSame( '<p><br />A</p>', getDataProcessor().toDataFormat( element ) );
     94                },
     95
     96                test_toDataFormat_6 : function()
     97                {
     98                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br></p></div>' );
     99
     100                        assert.areSame( '<p>A</p>', getDataProcessor().toDataFormat( element ) );
     101                },
     102
     103                test_toDataFormat_7 : function()
     104                {
     105                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p> \n  \n   A<br>  \n   \n   </p></div>' );
     106
     107                        assert.areSame( '<p>A</p>', getDataProcessor().toDataFormat( element ) );
     108                },
     109
     110                test_toDataFormat_8 : function()
     111                {
     112                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br><br></p></div>' );
     113
     114                        assert.areSame( '<p>A<br /><br /></p>', getDataProcessor().toDataFormat( element ) );
     115                },
     116
     117                test_toDataFormat_8 : function()
     118                {
     119                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><p>A<br><hr></p></div>' );
     120
     121                        // Both the following cases are acceptable. It depends on the way the browser parses the HTML.
     122                        try
     123                        {
     124                                // IE, Opera and Safari
     125                                assert.areSame( '<p>A</p><hr /><p></p>', getDataProcessor().toDataFormat( element ) );
     126                        }
     127                        catch ( e )
     128                        {
     129                                // FF
     130                                assert.areSame( '<p>A</p><hr />', getDataProcessor().toDataFormat( element ) );
     131                        }
     132                },
     133
     134                test_toDataFormat_ticket_2695 : function()
     135                {
     136                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><pre>\n\
     137FOR A = 0 TO 255\n\
     138   PRINT CHR$(A);\n\
     139NEXT A\n\
     140</pre></div>' );
     141
     142                        assert.areSame( '<pre>FOR A = 0 TO 255\n\
     143   PRINT CHR$(A);\n\
     144NEXT A\n\
     145</pre>', getDataProcessor().toDataFormat( element ).replace( /\r\n|\r|\n/g, '\n' ) );   // Normalize line breaks for IE
     146                },
     147
    82148                test_toDataFormat_ticket_2774 : function()
    83149                {
    84150                        var element = new CKEDITOR.dom.element.createFromHtml( '<div><P class=MsoNormal><B><I><SPAN lang=EN-US><o:p>Test</o:p></SPAN></I></B></P></div>' );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy