diff --git a/src/converters/downcast.js b/src/converters/downcast.js
index 109a1a57..f9c70b05 100644
--- a/src/converters/downcast.js
+++ b/src/converters/downcast.js
@@ -384,20 +384,19 @@ function createViewTableCellElement( tableWalkerValue, tableAttributes, insertPo
const tableCell = tableWalkerValue.cell;
- const isSingleParagraph = tableCell.childCount === 1 && tableCell.getChild( 0 ).name === 'paragraph';
+ const firstChild = tableCell.getChild( 0 );
+ const isSingleParagraph = tableCell.childCount === 1 && firstChild.name === 'paragraph';
conversionApi.writer.insert( insertPosition, cellElement );
- if ( isSingleParagraph ) {
+ if ( isSingleParagraph && !hasAnyAttribute( firstChild ) ) {
const innerParagraph = tableCell.getChild( 0 );
const paragraphInsertPosition = conversionApi.writer.createPositionAt( cellElement, 'end' );
conversionApi.consumable.consume( innerParagraph, 'insert' );
if ( options.asWidget ) {
- const containerName = [ ...innerParagraph.getAttributeKeys() ].length ? 'p' : 'span';
-
- const fakeParagraph = conversionApi.writer.createContainerElement( containerName );
+ const fakeParagraph = conversionApi.writer.createContainerElement( 'span' );
conversionApi.mapper.bindElements( innerParagraph, fakeParagraph );
conversionApi.writer.insert( paragraphInsertPosition, fakeParagraph );
@@ -554,3 +553,11 @@ function getViewTable( viewFigure ) {
}
}
}
+
+// Checks if element has any attribute set.
+//
+// @param {module:engine/model/element~Element element
+// @returns {Boolean}
+function hasAnyAttribute( element ) {
+ return !![ ...element.getAttributeKeys() ].length;
+}
diff --git a/tests/converters/downcast.js b/tests/converters/downcast.js
index d2ce2b42..d80b6bb2 100644
--- a/tests/converters/downcast.js
+++ b/tests/converters/downcast.js
@@ -147,6 +147,35 @@ describe( 'downcast converters', () => {
) );
} );
+ it( 'should create table with block content (attribute on paragraph)', () => {
+ editor.conversion.attributeToAttribute(
+ {
+ model: { key: 'alignment', values: [ 'right', 'center', 'justify' ] },
+ view: {
+ right: { key: 'style', value: { 'text-align': 'right' } },
+ center: { key: 'style', value: { 'text-align': 'center' } },
+ justify: { key: 'style', value: { 'text-align': 'justify' } }
+ }
+ }
+ );
+
+ setModelData( model, modelTable( [
+ [ '00' ]
+ ] ) );
+
+ expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formatTable(
+ '' +
+ '' +
+ '' +
+ '' +
+ '00 | ' +
+ '
' +
+ '' +
+ '
' +
+ ' '
+ ) );
+ } );
+
it( 'should be possible to overwrite', () => {
editor.conversion.elementToElement( { model: 'tableRow', view: 'tr', converterPriority: 'high' } );
editor.conversion.elementToElement( { model: 'tableCell', view: 'td', converterPriority: 'high' } );