|
|
@@ -111,50 +111,28 @@ export function skipEmptyTableRow() {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-export function upcastTableCell( elementName ) {
|
|
|
+/**
|
|
|
+ * Converter that ensures empty paragraph is inserted in a table cell if no other content was converted.
|
|
|
+ *
|
|
|
+ * @returns {Function} Conversion helper.
|
|
|
+ */
|
|
|
+export function ensureParagraphInTableCell( elementName ) {
|
|
|
return dispatcher => {
|
|
|
dispatcher.on( `element:${ elementName }`, ( evt, data, conversionApi ) => {
|
|
|
- const viewTableCell = data.viewItem;
|
|
|
-
|
|
|
- // When element was already consumed then skip it.
|
|
|
- if ( !conversionApi.consumable.test( viewTableCell, { name: true } ) ) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const tableCell = conversionApi.writer.createElement( 'tableCell' );
|
|
|
-
|
|
|
- // Insert element on allowed position.
|
|
|
- const splitResult = conversionApi.splitToAllowedParent( tableCell, data.modelCursor );
|
|
|
-
|
|
|
- // When there is no split result it means that we can't insert element to model tree, so let's skip it.
|
|
|
- if ( !splitResult ) {
|
|
|
+ // The default converter will create a model range on converted table cell.
|
|
|
+ if ( !data.modelRange ) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- conversionApi.writer.insert( tableCell, splitResult.position );
|
|
|
- conversionApi.consumable.consume( viewTableCell, { name: true } );
|
|
|
+ const tableCell = data.modelRange.start.nodeAfter;
|
|
|
|
|
|
- conversionApi.convertChildren( viewTableCell, tableCell );
|
|
|
-
|
|
|
- // Ensure a paragraph in the model for empty table cells.
|
|
|
+ // Ensure a paragraph in the model for empty table cells for converted table cells.
|
|
|
if ( !tableCell.childCount ) {
|
|
|
- conversionApi.writer.insertElement( 'paragraph', tableCell, 0 );
|
|
|
- }
|
|
|
+ const modelCursor = conversionApi.writer.createPositionAt( tableCell, 0 );
|
|
|
|
|
|
- // Set conversion result range.
|
|
|
- data.modelRange = conversionApi.writer.createRange(
|
|
|
- // Range should start before inserted element
|
|
|
- conversionApi.writer.createPositionBefore( tableCell ),
|
|
|
- // Should end after but we need to take into consideration that children could split our
|
|
|
- // element, so we need to move range after parent of the last converted child.
|
|
|
- // before: <allowed>[]</allowed>
|
|
|
- // after: <allowed>[<converted><child></child></converted><child></child><converted>]</converted></allowed>
|
|
|
- conversionApi.writer.createPositionAfter( tableCell )
|
|
|
- );
|
|
|
-
|
|
|
- // Continue after inserted element.
|
|
|
- data.modelCursor = data.modelRange.end;
|
|
|
- } );
|
|
|
+ conversionApi.writer.insertElement( 'paragraph', modelCursor );
|
|
|
+ }
|
|
|
+ }, { priority: 'low' } );
|
|
|
};
|
|
|
}
|
|
|
|