소스 검색

Merge pull request #112 from ckeditor/t/ckeditor5/1246

Fix: The upcast conversion now properly parses inline content in table cell into single paragraph. Closes ckeditor/ckeditor5#1246.
Szymon Cofalik 7 년 전
부모
커밋
3c259e5bc7
2개의 변경된 파일24개의 추가작업 그리고 6개의 파일을 삭제
  1. 5 6
      packages/ckeditor5-table/src/converters/upcasttable.js
  2. 19 0
      packages/ckeditor5-table/tests/converters/upcasttable.js

+ 5 - 6
packages/ckeditor5-table/src/converters/upcasttable.js

@@ -115,13 +115,12 @@ export function upcastTableCell( elementName ) {
 			conversionApi.writer.insert( tableCell, splitResult.position );
 			conversionApi.consumable.consume( viewTableCell, { name: true } );
 
-			for ( const child of viewTableCell.getChildren() ) {
-				const { modelCursor } = conversionApi.convertItem( child, ModelPosition.createAt( tableCell, 'end' ) );
+			const modelCursor = ModelPosition.createAt( tableCell );
+			conversionApi.convertChildren( viewTableCell, modelCursor );
 
-				// Ensure empty paragraph in table cell.
-				if ( modelCursor.parent.name == 'tableCell' && !modelCursor.parent.childCount ) {
-					conversionApi.writer.insertElement( 'paragraph', modelCursor );
-				}
+			// Ensure a paragraph in the model for empty table cells.
+			if ( !tableCell.childCount ) {
+				conversionApi.writer.insertElement( 'paragraph', modelCursor );
 			}
 
 			// Set conversion result range.

+ 19 - 0
packages/ckeditor5-table/tests/converters/upcasttable.js

@@ -418,6 +418,25 @@ describe( 'upcastTable()', () => {
 			] ) );
 		} );
 
+		it( 'should upcast table inline content to single <paragraph>', () => {
+			editor.model.schema.extend( '$text', { allowAttributes: 'bold' } );
+			editor.conversion.attributeToElement( { model: 'bold', view: 'strong' } );
+
+			editor.setData(
+				'<table>' +
+					'<tbody>' +
+						'<tr>' +
+							'<td>foo <strong>bar</strong></td>' +
+						'</tr>' +
+					'</tbody>' +
+				'</table>'
+			);
+
+			expectModel( modelTable( [
+				[ 'foo <$text bold="true">bar</$text>' ]
+			] ) );
+		} );
+
 		it( 'should upcast table with multiple <p> in table cell', () => {
 			editor.setData(
 				'<table>' +