ソースを参照

Changed: Properly mark th in thead.

Maciej Gołaszewski 7 年 前
コミット
3d0ce07b98

+ 14 - 3
packages/ckeditor5-table/src/converters.js

@@ -68,15 +68,17 @@ export function upcastTable() {
 
 export function downcastTableCell() {
 	return dispatcher => dispatcher.on( 'insert:tableCell', ( evt, data, conversionApi ) => {
-		if ( !conversionApi.consumable.consume( data.item, 'insert' ) ) {
+		const tableCell = data.item;
+
+		if ( !conversionApi.consumable.consume( tableCell, 'insert' ) ) {
 			return;
 		}
 
-		const tableCellElement = conversionApi.writer.createContainerElement( 'td' );
+		const tableCellElement = conversionApi.writer.createContainerElement( isHead( tableCell ) ? 'th' : 'td' );
 
 		const viewPosition = conversionApi.mapper.toViewPosition( data.range.start );
 
-		conversionApi.mapper.bindElements( data.item, tableCellElement );
+		conversionApi.mapper.bindElements( tableCell, tableCellElement );
 		conversionApi.writer.insert( viewPosition, tableCellElement );
 	}, { priority: 'normal' } );
 }
@@ -195,3 +197,12 @@ function _createModelRow( row, rows, conversionApi, firstThead ) {
 	}
 }
 
+function isHead( tableCell ) {
+	const row = tableCell.parent;
+	const table = row.parent;
+	const rowIndex = table.getChildIndex( row );
+	const headingRows = table.getAttribute( 'headingRows' );
+
+	return headingRows && headingRows > rowIndex;
+}
+

+ 3 - 3
packages/ckeditor5-table/tests/converters.js

@@ -274,7 +274,7 @@ describe( 'Table converters', () => {
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
 				'<table>' +
 				'<thead>' +
-				'<tr><td>1</td></tr>' +
+				'<tr><th>1</th></tr>' +
 				'</thead>' +
 				'<tbody>' +
 				'<tr><td>2</td></tr>' +
@@ -294,8 +294,8 @@ describe( 'Table converters', () => {
 			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
 				'<table>' +
 				'<thead>' +
-				'<tr><td>1</td></tr>' +
-				'<tr><td>2</td></tr>' +
+				'<tr><th>1</th></tr>' +
+				'<tr><th>2</th></tr>' +
 				'</thead>' +
 				'</table>'
 			);

+ 2 - 2
packages/ckeditor5-table/tests/tableediting.js

@@ -43,7 +43,7 @@ describe( 'TableEditing', () => {
 			it( 'should create thead section', () => {
 				setModelData( model, '<table headingRows="1"><tableRow><tableCell>foo[]</tableCell></tableRow></table>' );
 
-				expect( editor.getData() ).to.equal( '<table><thead><tr><td>foo</td></tr></thead></table>' );
+				expect( editor.getData() ).to.equal( '<table><thead><tr><th>foo</th></tr></thead></table>' );
 			} );
 
 			it( 'should create thead and tbody sections in proper order', () => {
@@ -55,7 +55,7 @@ describe( 'TableEditing', () => {
 				);
 
 				expect( editor.getData() ).to.equal( '<table>' +
-					'<thead><tr><td>foo</td></tr></thead>' +
+					'<thead><tr><th>foo</th></tr></thead>' +
 					'<tbody><tr><td>bar</td></tr><tr><td>baz</td></tr></tbody>' +
 					'</table>'
 				);