Parcourir la source

The feature converter is more detailed.

Kamil Piechaczek il y a 6 ans
Parent
commit
a85caad5b0

+ 8 - 2
packages/ckeditor5-page-break/src/pagebreakediting.js

@@ -74,8 +74,14 @@ export default class PageBreakEditing extends Plugin {
 
 					const viewSpan = first( element.getChildren() );
 
-					// The child must be the "span" element that is not displayed and doesn't have any child.
-					if ( !viewSpan.is( 'span' ) || viewSpan.getStyle( 'display' ) != 'none' || viewSpan.childCount != 0 ) {
+					// The child must be the "span" element that is not displayed and has a space inside.
+					if ( !viewSpan.is( 'span' ) || viewSpan.getStyle( 'display' ) != 'none' || viewSpan.childCount != 1 ) {
+						return;
+					}
+
+					const text = first( viewSpan.getChildren() );
+
+					if ( !text.is( 'text' ) || text.data !== ' ' ) {
 						return;
 					}
 

+ 15 - 1
packages/ckeditor5-page-break/tests/pagebreakediting.js

@@ -82,7 +82,7 @@ describe( 'PageBreakEditing', () => {
 				editor.setData( '<div><div style="page-break-after:always;"><span style="display:none;">&nbsp;</span></div></div>' );
 
 				expect( getModelData( model, { withoutSelection: true } ) )
-					.to.equal( '<div></div>' );
+					.to.equal( '<div> </div>' );
 			} );
 
 			it( 'should not convert if outer div has wrong styles', () => {
@@ -186,6 +186,20 @@ describe( 'PageBreakEditing', () => {
 				expect( getModelData( model, { withoutSelection: true } ) )
 					.to.equal( '<pageBreak></pageBreak><section><$text foo="true">Foo</$text></section>' );
 			} );
+
+			it( 'should not convert if inner span has no children', () => {
+				editor.setData( '<div style="page-break-after:always;"><span style="display:none;"></span></div>' );
+
+				expect( getModelData( model, { withoutSelection: true } ) )
+					.to.equal( '' );
+			} );
+
+			it( 'should not convert if inner span has other element as a child', () => {
+				editor.setData( '<div style="page-break-after:always;"><span style="display:none;"><span></span></span></div>' );
+
+				expect( getModelData( model, { withoutSelection: true } ) )
+					.to.equal( '' );
+			} );
 		} );
 	} );