|
@@ -97,16 +97,28 @@ function fixTableRow( tableRow, writer ) {
|
|
|
return wasFixed;
|
|
return wasFixed;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Fixes all table cell content by adding paragraph to a table cell without any child.
|
|
|
|
|
|
|
+// Fixes all table cell content by:
|
|
|
|
|
+// - adding paragraph to a table cell without any child.
|
|
|
|
|
+// - wrapping direct $text in <paragraph>.
|
|
|
//
|
|
//
|
|
|
// @param {module:engine/model/element~Element} table
|
|
// @param {module:engine/model/element~Element} table
|
|
|
// @param {module:engine/model/writer~Writer} writer
|
|
// @param {module:engine/model/writer~Writer} writer
|
|
|
|
|
+// @returns {Boolean}
|
|
|
function fixTableCellContent( tableCell, writer ) {
|
|
function fixTableCellContent( tableCell, writer ) {
|
|
|
|
|
+ // Insert paragraph to an empty table cell.
|
|
|
if ( tableCell.childCount == 0 ) {
|
|
if ( tableCell.childCount == 0 ) {
|
|
|
writer.insertElement( 'paragraph', tableCell );
|
|
writer.insertElement( 'paragraph', tableCell );
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ // Check table cell children for directly placed $text nodes.
|
|
|
|
|
+ const textNodes = Array.from( tableCell.getChildren() ).filter( child => child.is( 'text' ) );
|
|
|
|
|
+
|
|
|
|
|
+ for ( const child of textNodes ) {
|
|
|
|
|
+ writer.wrap( writer.createRangeOn( child ), 'paragraph' );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Return true when there were text nodes to fix.
|
|
|
|
|
+ return !!textNodes.length;
|
|
|
}
|
|
}
|