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

Commit

Permalink
Fix: The upcast conversion now properly parses inline content in tabl…
Browse files Browse the repository at this point in the history
…e cell into single paragraph.
  • Loading branch information
jodator committed Sep 18, 2018
1 parent 0a53042 commit 4f9179b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/converters/upcasttable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/converters/upcasttable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>' +
Expand Down

0 comments on commit 4f9179b

Please sign in to comment.