Ticket #2886: 2886_4.patch

File 2886_4.patch, 7.8 KB (added by Martin Kou, 15 years ago)
  • _source/plugins/htmldataprocessor/plugin.js

     
    55
    66(function()
    77{
     8        function blockNeedsExtension( block )
     9        {
     10                if ( block.children.length < 1 )
     11                        return true;
     12
     13                var lastChild = block.children[ block.children.length - 1 ];
     14                return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';
     15        }
     16
     17        function extendBlockForDisplay( block )
     18        {
     19                if ( blockNeedsExtension( block ) )
     20                {
     21                        if ( CKEDITOR.env.ie )
     22                                block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) );
     23                        else
     24                                block.children.push( new CKEDITOR.htmlParser.element( 'br', {} ) );
     25                }
     26        }
     27
     28        function extendBlockForOutput( block )
     29        {
     30                if ( blockNeedsExtension( block ) )
     31                        block.children.push( new CKEDITOR.htmlParser.text( '\xa0' ) );
     32        }
     33
     34        var dtd = CKEDITOR.dtd;
     35       
     36        // $tableContent is replaced by two select tags because tags like tbody should
     37        // not be extended.
     38        var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, { td : 1, th : 1 } );
     39
    840        var defaultDataFilterRules =
    941        {
    1042                elementNames :
     
    1850                        // Event attributes (onXYZ) must not be directly set. They can become
    1951                        // active in the editing area (IE|WebKit).
    2052                        [ ( /^on/ ), '_cke_pa_on' ]
    21                 ]
     53                ],
     54
     55                elements : {}
    2256        };
    2357
     58        for ( var i in blockLikeTags )
     59                defaultDataFilterRules.elements[ i ] = extendBlockForDisplay;
     60
    2461        /**
    2562         * IE sucks with dynamic 'name' attribute after element is created, '_cke_saved_name' is used instead for this attribute.
    2663         */
     
    102139                                }
    103140                        }
    104141                };
     142       
     143        for ( var i in blockLikeTags )
     144                defaultHtmlFilterRules.elements[ i ] = extendBlockForOutput;
    105145
    106146        if ( CKEDITOR.env.ie )
    107147        {
  • _source/tests/plugins/htmldataprocessor/htmldataprocessor.html

     
    33<head>
    44        <title>Plugin: htmldataprocessor</title>
    55        <link rel="stylesheet" type="text/css" href="../../test.css" />
    6         <script type="text/javascript" src="../../../../ckeditor_source.js"></script>
     6        <script type="text/javascript" src="../../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE%
     7        <script type="text/javascript" src="../../../ckeditor.js"></script>
     8        %REMOVE_LINE% -->
    79        <script type="text/javascript" src="../../test.js"></script>
    810        <script type="text/javascript">
    911
     
    102104                                getDataProcessor().toDataFormat( '<INPUT type="checkbox" UNKNOWN  autocomplete=off>' ) );
    103105                },
    104106
     107                test_toDataFormat_ticket_2886_1 : function()
     108                {
     109                        var editor = CKEDITOR.instances.editor1;
     110                        var test = this;
     111                        var isReady = !!editor.dataProcessor;
     112
     113                        if ( !isReady )
     114                        {
     115                                editor.on( 'instanceReady', function()
     116                                {
     117                                        isReady = true;
     118                                } );
     119                        }
     120
     121                        this.wait( function()
     122                                {
     123                                        if ( !isReady )
     124                                        {
     125                                                test.wait( arguments.callee, 100 );
     126                                                return;
     127                                        }
     128
     129                                        assert.areSame( '<p>\n\t&nbsp;</p>\n',
     130                                                editor.dataProcessor.toDataFormat( '<p></p>' ) );
     131                                }, 100 );
     132                },
     133
     134                test_toDataFormat_ticket_2886_2 : function()
     135                {
     136                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     137
     138                        var source = '<p>Some text<br><br><br></p>';
     139                        if ( CKEDITOR.env.ie )
     140                                source = '<p>Some text<br><br></p>';
     141                        assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t&nbsp;</p>\n',
     142                                dataProcessor.toDataFormat( source ) );
     143                },
     144
     145                test_toDataFormat_ticket_2886_3 : function()
     146                {
     147                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     148
     149                        assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t<br />\n\tSome more text</p>\n',
     150                                dataProcessor.toDataFormat( '<p>Some text<br><br><br>Some more text</p>' ) );
     151                },
     152
     153                test_toDataFormat_ticket_2886_4 : function()
     154                {
     155                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     156
     157                        assert.areSame( '<p>\n\tSome text<br />\n\t<br />\n\t&nbsp;</p>\n',
     158                                dataProcessor.toDataFormat( '<p>Some text<br><br>&nbsp;</p>' ) );
     159                },
     160
     161                test_toDataFormat_ticket_2886_5 : function()
     162                {
     163                        if ( CKEDITOR.env.ie )
     164                                return;
     165
     166                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     167
     168                        assert.areSame( '<p>\n\t&nbsp;</p>\n',
     169                                dataProcessor.toDataFormat( '<p><br></p>' ) );
     170                },
     171
     172                test_toDataFormat_ticket_2886_6 : function()
     173                {
     174                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     175
     176                        var source = '<p><br><br></p>';
     177                        if ( CKEDITOR.env.ie )
     178                                source = '<p><br></p>';
     179
     180                        assert.areSame( '<p>\n\t<br />\n\t&nbsp;</p>\n',
     181                                dataProcessor.toDataFormat( source ) );
     182                },
     183
     184                test_toHtml_ticket_2886_1 : function()
     185                {
     186                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     187
     188                        var expected = '<p><br /></p>';
     189                        if ( CKEDITOR.env.ie )
     190                                expected = '<p>\xa0</p>';
     191                        assert.areSame( expected, dataProcessor.toHtml( '<p></p>' ) );
     192                },
     193
     194                test_toHtml_ticket_2886_2 : function()
     195                {
     196                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     197
     198                        var expected = '<p>Some text<br />Some other text</p>';
     199                        assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br>Some other text</p>' ) );
     200                },
     201
     202                test_toHtml_ticket_2886_3 : function()
     203                {
     204                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     205
     206                        var expected = '<p>Some text<br /><br /></p>';
     207                        if ( CKEDITOR.env.ie )
     208                                expected = '<p>Some text<br />\xa0</p>';
     209                        assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br>&nbsp;</p>' ) );
     210                },
     211
    105212                name : document.title
    106213        };
    107214})() );
     
    115222        </script>
    116223</head>
    117224<body>
     225        <textarea id="editor1" class="ckeditor" cols="80" rows="10"></textarea>
    118226</body>
    119227</html>
  • _source/core/htmlparser/fragment.js

     
    4747                        {table:1,ul:1,ol:1,dl:1},
    4848                        CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl );
    4949
     50        // Regex to scan for &nbsp; at the end of blocks, which is actually placeholders.
     51        var tailNbspRegex = /^[\t\r\n ]*&nbsp;$/;
     52
    5053        /**
    5154         * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string.
    5255         * @param {String} fragmentHtml The HTML to be parsed, filling the fragment.
     
    117120                                        currentNode = savedCurrent;
    118121                        }
    119122
    120                         // Rtrim empty spaces on block end boundary. (#3585)
    121123                        if ( element._.isBlockLike )
    122124                        {
    123 
    124                                 var length = element.children.length,
    125                                         lastChild = element.children[ length - 1 ],
     125                                // Rtrim empty spaces on block end boundary. (#3585)
     126                                var children = element.children,
     127                                        lastChild = children[ children.length - 1 ],
    126128                                        text;
    127129                                if ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT )
    128130                                {
    129131                                        if ( !( text = CKEDITOR.tools.rtrim( lastChild.value ) ) )
    130                                                 element.children.length = length -1;
     132                                                children.pop();
    131133                                        else
    132134                                                lastChild.value = text;
    133135                                }
     136                       
     137                                // If the current node is a block, and the current browser is not IE; then
     138                                // search for and remove the tailing BR node, if any. (#2862)
     139                                lastChild = children[ children.length - 1 ];
     140                                if ( lastChild )
     141                                {
     142                                        if ( !CKEDITOR.env.ie && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' )
     143                                                children.pop();
     144                                        if ( lastChild.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( lastChild.value ) )
     145                                                children.pop();
     146                                }
    134147                        }
    135148
    136149                        target.add( element );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy