Sfoglia il codice sorgente

Tests: Add tests for converting single paragraph with attributes.

Maciej Gołaszewski 7 anni fa
parent
commit
c279b3af78

+ 3 - 1
packages/ckeditor5-table/src/converters/downcast.js

@@ -386,7 +386,9 @@ function createViewTableCellElement( tableWalkerValue, tableAttributes, insertPo
 		conversionApi.consumable.consume( innerParagraph, 'insert' );
 
 		if ( options.asWidget ) {
-			const fakeParagraph = conversionApi.writer.createContainerElement( 'span' );
+			const containerName = [ ...innerParagraph.getAttributeKeys() ].length ? 'p' : 'span';
+
+			const fakeParagraph = conversionApi.writer.createContainerElement( containerName );
 
 			conversionApi.mapper.bindElements( innerParagraph, fakeParagraph );
 			conversionApi.writer.insert( paragraphInsertPosition, fakeParagraph );

+ 1 - 0
packages/ckeditor5-table/src/converters/tablecell-post-fixer.js

@@ -82,6 +82,7 @@ function tableCellPostFixer( writer, model, mapper ) {
 				}
 			} else {
 				const singleChild = tableCell.getChild( 0 );
+
 				if ( !singleChild || !singleChild.is( 'paragraph' ) ) {
 					return;
 				}

+ 13 - 0
packages/ckeditor5-table/tests/converters/downcast.js

@@ -1199,5 +1199,18 @@ describe( 'downcast converters', () => {
 				[ '<p>00</p><p></p>' ]
 			], { asWidget: true } ) );
 		} );
+
+		it( 'should rename <span> to <p> for single paragraph with attribute', () => {
+			model.schema.extend( '$block', { allowAttributes: 'foo' } );
+			editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
+
+			setModelData( model, modelTable( [
+				[ '<paragraph foo="bar">00[]</paragraph>' ]
+			] ) );
+
+			expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formattedViewTable( [
+				[ '<p foo="bar">00</p>' ]
+			], { asWidget: true } ) );
+		} );
 	} );
 } );

+ 35 - 1
packages/ckeditor5-table/tests/converters/tablecell-post-fixer.js

@@ -90,7 +90,41 @@ describe( 'TableCell post-fixer', () => {
 		], { asWidget: true } ) );
 	} );
 
-	it( 'should do nothing on rename <paragraph> to <heading1> ', () => {
+	it( 'should rename <span> to <p> when setting attribute on paragraph', () => {
+		model.schema.extend( '$block', { allowAttributes: 'foo' } );
+		editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
+
+		setModelData( model, modelTable( [ [ '<paragraph>00[]</paragraph>' ] ] ) );
+
+		const table = root.getChild( 0 );
+
+		model.change( writer => {
+			writer.setAttribute( 'foo', 'bar', table.getNodeByPath( [ 0, 0, 0 ] ) );
+		} );
+
+		expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formattedViewTable( [
+			[ '<p foo="bar">00</p>' ]
+		], { asWidget: true } ) );
+	} );
+
+	it( 'should rename <p> to <span> when removing attribute from paragraph', () => {
+		model.schema.extend( '$block', { allowAttributes: 'foo' } );
+		editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
+
+		setModelData( model, modelTable( [ [ '<paragraph foo="bar">00[]</paragraph>' ] ] ) );
+
+		const table = root.getChild( 0 );
+
+		model.change( writer => {
+			writer.removeAttribute( 'foo', table.getNodeByPath( [ 0, 0, 0 ] ) );
+		} );
+
+		expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formattedViewTable( [
+			[ '<span>00</span>' ]
+		], { asWidget: true } ) );
+	} );
+
+	it( 'should do nothing on rename <paragraph> to <heading1>', () => {
 		setModelData( model, modelTable( [ [ '00' ] ] ) );
 
 		const table = root.getChild( 0 );