Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ea1e16d

Browse files
authored
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.
2 parents 77d96a4 + 4f9179b commit ea1e16d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/converters/upcasttable.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,12 @@ export function upcastTableCell( elementName ) {
115115
conversionApi.writer.insert( tableCell, splitResult.position );
116116
conversionApi.consumable.consume( viewTableCell, { name: true } );
117117

118-
for ( const child of viewTableCell.getChildren() ) {
119-
const { modelCursor } = conversionApi.convertItem( child, ModelPosition.createAt( tableCell, 'end' ) );
118+
const modelCursor = ModelPosition.createAt( tableCell );
119+
conversionApi.convertChildren( viewTableCell, modelCursor );
120120

121-
// Ensure empty paragraph in table cell.
122-
if ( modelCursor.parent.name == 'tableCell' && !modelCursor.parent.childCount ) {
123-
conversionApi.writer.insertElement( 'paragraph', modelCursor );
124-
}
121+
// Ensure a paragraph in the model for empty table cells.
122+
if ( !tableCell.childCount ) {
123+
conversionApi.writer.insertElement( 'paragraph', modelCursor );
125124
}
126125

127126
// Set conversion result range.

tests/converters/upcasttable.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,25 @@ describe( 'upcastTable()', () => {
418418
] ) );
419419
} );
420420

421+
it( 'should upcast table inline content to single <paragraph>', () => {
422+
editor.model.schema.extend( '$text', { allowAttributes: 'bold' } );
423+
editor.conversion.attributeToElement( { model: 'bold', view: 'strong' } );
424+
425+
editor.setData(
426+
'<table>' +
427+
'<tbody>' +
428+
'<tr>' +
429+
'<td>foo <strong>bar</strong></td>' +
430+
'</tr>' +
431+
'</tbody>' +
432+
'</table>'
433+
);
434+
435+
expectModel( modelTable( [
436+
[ 'foo <$text bold="true">bar</$text>' ]
437+
] ) );
438+
} );
439+
421440
it( 'should upcast table with multiple <p> in table cell', () => {
422441
editor.setData(
423442
'<table>' +

0 commit comments

Comments
 (0)