Skip to content

Commit

Permalink
Merge branch 't/10422'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Jul 4, 2014
2 parents 00ca2c0 + f434098 commit ab195ef
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ CKEditor 4 Changelog

Fixed Issues:

* [#10422](http://dev.ckeditor.com/ticket/10422): Fixed: [`config.fillEmptyBlocks`](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-fillEmptyBlocks) not working properly if a function is specified.
* [#12110](http://dev.ckeditor.com/ticket/12110): Fixed: Editor crash after deleting a table. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
* [#11897](http://dev.ckeditor.com/ticket/11897): Fixed: Enter key in an empty formatted list item, creates a new line instead of breaking the list. Thanks to [noam-si](https://github.com/noam-si)!
* [#12140](http://dev.ckeditor.com/ticket/12140): Fixed: Double-clicking linked widgets opens two dialogs.
Expand Down
23 changes: 11 additions & 12 deletions core/htmldataprocessor.js
Expand Up @@ -307,16 +307,15 @@
function blockFilter( isOutput, fillEmptyBlock ) {

return function( block ) {

// DO NOT apply the filer if it's a fragment node.
// DO NOT apply the filler if it's a fragment node.
if ( block.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT )
return;

cleanBogus( block );

if ( ( typeof fillEmptyBlock == 'function' ? fillEmptyBlock( block ) !== false : fillEmptyBlock ) &&
isEmptyBlockNeedFiller( block ) )
{
var shouldFillBlock = typeof fillEmptyBlock == 'function' ? fillEmptyBlock( block ) : fillEmptyBlock;

if ( shouldFillBlock !== false && isEmptyBlockNeedFiller( block ) ) {
block.add( createFiller( isOutput ) );
}
};
Expand Down Expand Up @@ -446,21 +445,21 @@
return !last || block.name == 'form' && last.name == 'input' ;
}

var rules = { elements: {} };
var isOutput = type == 'html';
var rules = { elements: {} },
isOutput = type == 'html',
textBlockTags = CKEDITOR.tools.extend( {}, blockLikeTags );

// Build the list of text blocks.
var textBlockTags = CKEDITOR.tools.extend( {}, blockLikeTags );
for ( var i in textBlockTags ) {
if ( !( '#' in dtd[ i ] ) )
delete textBlockTags[ i ];
}

for ( i in textBlockTags )
rules.elements[ i ] = blockFilter( isOutput, editor.config.fillEmptyBlocks !== false );
rules.elements[ i ] = blockFilter( isOutput, editor.config.fillEmptyBlocks );

// Editable element is to be checked separately.
rules.root = blockFilter( isOutput );
// Editable element has to be checked separately.
rules.root = blockFilter( isOutput, false );
rules.elements.br = brFilter( isOutput );
return rules;
}
Expand Down Expand Up @@ -928,7 +927,7 @@
* };
*
* @since 3.5
* @cfg {Boolean} [fillEmptyBlocks=true]
* @cfg {Boolean/Function} [fillEmptyBlocks=true]
* @member CKEDITOR.config
*/

Expand Down
84 changes: 69 additions & 15 deletions tests/core/htmldataprocessor.js
@@ -1,6 +1,9 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: entities,list,htmlwriter */

( function() {
'use strict';

CKEDITOR.tools.enableHtml5Elements( document );

/**
Expand Down Expand Up @@ -65,8 +68,6 @@
};
}

window.alert = function() {};

var tcs = {
// These tests go far beyond the strict htmlDataProcessor code testing. We
// are actually testing the entire parsing system here. The combination of
Expand Down Expand Up @@ -100,16 +101,37 @@
fullPage: true,
allowedContent: true
}
},
editor4: {
creator: 'inline',
name: 'test_editor4',
config: {
fillEmptyBlocks: false,
allowedContent: true
}
},
editor5: {
creator: 'inline',
name: 'test_editor5',
config: {
fillEmptyBlocks: function( el ) {
// Do not refactor - should return undefined in other cases.
if ( el.name == 'h1' )
return false;
},
allowedContent: true
}
}
}, function( editors, bots ) {
that.editorBot = bots.editor;
that.editor = editors.editor;
var num, name;

that.editorBot2 = bots.editor2;
that.editor2 = editors.editor2;
for ( name in editors ) {
num = name.match( /\d+/ );
num = num ? num[ 0 ] : '';

that.editorBot3 = bots.editor3;
that.editor3 = editors.editor3;
that[ name ] = editors[ name ];
that[ 'editorBot' + num ] = bots[ name ];
}

that.callback();
} );
Expand Down Expand Up @@ -526,7 +548,7 @@
for ( var i = 0, processor = this.editor.dataProcessor; i < sources.length; ++i ) {
assert.areSame(
results[ i ],
processor.toHtml( sources[ i ] )
bender.tools.compatHtml( processor.toHtml( sources[ i ] ), false, true )
// IE encodes \n in attributes.
.replace( /&#10;/g, '\n' ),
'tc ' + i
Expand Down Expand Up @@ -660,7 +682,7 @@

'test process style': function() {
var p = this.editor.dataProcessor,
ss = '<p>X</p><style>'
ss = '<p>X</p><style>',
se = '</style><p>X</p>';

assert.areSame( ss + 'a{}' + se, toHtml( ss + 'a{}' + se ), 's1' );
Expand Down Expand Up @@ -1023,6 +1045,42 @@
assert.areSame( '<p>foo</p>', htmlDP.toDataFormat( '<p data-cke-expando="1">foo</p>' ), 'toDF' );
assert.areSame( '<p contenteditable="false">foo</p>', htmlDP.toHtml( '<p contenteditable="false" data-cke-expando="1">foo</p>' ), 'toHtml - non editable' );
assert.areSame( '<p contenteditable="false">foo</p>', htmlDP.toHtml( '<p contenteditable="false" data-cke-expando="1">foo</p>' ), 'toDF - non editable' );
},

'test config.fillEmptyBlocks - default': function() {
var htmlDP = this.editor.dataProcessor,
bogus = CKEDITOR.env.needsBrFiller ? '<br />' : '';

assert.areSame( '<p>' + bogus + '</p>', htmlDP.toHtml( '<p></p>' ), 'toHtml 1' );
assert.areSame( '<div><h1>' + bogus + '</h1></div>', htmlDP.toHtml( '<div><h1></h1></div>' ), 'toHtml 2' );

bogus = '&nbsp;';

assert.areSame( '<p>' + bogus + '</p>', htmlDP.toDataFormat( '<p></p>' ), 'toDF 1' );
assert.areSame( '<div><h1>' + bogus + '</h1></div>', htmlDP.toDataFormat( '<div><h1></h1></div>' ), 'toDF 2' );
},

'test config.fillEmptyBlocks - false': function() {
var htmlDP = this.editor4.dataProcessor;

assert.areSame( '<p></p>', htmlDP.toHtml( '<p></p>' ), 'toHtml 1' );
assert.areSame( '<div><h1></h1></div>', htmlDP.toHtml( '<div><h1></h1></div>' ), 'toHtml 1' );

assert.areSame( '<p></p>', htmlDP.toDataFormat( '<p></p>' ), 'toDF 1' );
assert.areSame( '<div><h1></h1></div>', htmlDP.toDataFormat( '<div><h1></h1></div>' ), 'toDF 2' );
},

'test config.fillEmptyBlocks - callback': function() {
var htmlDP = this.editor5.dataProcessor,
bogus = CKEDITOR.env.needsBrFiller ? '<br />' : '';

assert.areSame( '<p>' + bogus + '</p>', htmlDP.toHtml( '<p></p>' ), 'toHtml 1' );
assert.areSame( '<h1></h1>', htmlDP.toHtml( '<h1></h1>' ), 'toHtml 1' );

bogus = '&nbsp;';

assert.areSame( '<p>' + bogus + '</p>', htmlDP.toDataFormat( '<p></p>' ), 'toDF 1' );
assert.areSame( '<h1></h1>', htmlDP.toDataFormat( '<h1></h1>' ), 'toDF 2' );
}
};

Expand Down Expand Up @@ -1099,8 +1157,4 @@
'<p><onxxx>foo</onxxx>bar</p>' );
}

alert( '>' );

<!--
alert( '-->' );
//-->
} )();

0 comments on commit ab195ef

Please sign in to comment.