Skip to content

Commit

Permalink
Paste: preserve empty table cells (#14137)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Mar 6, 2019
1 parent e3b5d61 commit 7de6ef4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/block-library/src/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import edit from './edit';

const tableContentPasteSchema = {
tr: {
allowEmpty: true,
children: {
th: {
allowEmpty: true,
children: getPhrasingContentSchema(),
},
td: {
allowEmpty: true,
children: getPhrasingContentSchema(),
},
},
Expand All @@ -33,12 +36,15 @@ const tablePasteSchema = {
table: {
children: {
thead: {
allowEmpty: true,
children: tableContentPasteSchema,
},
tfoot: {
allowEmpty: true,
children: tableContentPasteSchema,
},
tbody: {
allowEmpty: true,
children: tableContentPasteSchema,
},
},
Expand Down
10 changes: 8 additions & 2 deletions packages/blocks/src/api/raw-handling/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,17 @@ function cleanNodeList( nodeList, doc, schema, inline ) {
( ! schema[ tag ].isMatch || schema[ tag ].isMatch( node ) )
) {
if ( node.nodeType === ELEMENT_NODE ) {
const { attributes = [], classes = [], children, require = [] } = schema[ tag ];
const {
attributes = [],
classes = [],
children,
require = [],
allowEmpty,
} = schema[ tag ];

// If the node is empty and it's supposed to have children,
// remove the node.
if ( isEmpty( node ) && children ) {
if ( children && ! allowEmpty && isEmpty( node ) ) {
remove( node );
return;
}
Expand Down
4 changes: 4 additions & 0 deletions test/integration/fixtures/markdown-in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ First Header | Second Header
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column

| | |
|---|---|
| | Table with empty cells. |

## Quote

> First
Expand Down
4 changes: 4 additions & 0 deletions test/integration/fixtures/markdown-out.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ <h2>Table</h2>
<table class="wp-block-table"><thead><tr><th>First Header</th><th>Second Header</th></tr></thead><tbody><tr><td>Content from cell 1</td><td>Content from cell 2</td></tr><tr><td>Content in the first column</td><td>Content in the second column</td></tr></tbody></table>
<!-- /wp:table -->

<!-- wp:table -->
<table class="wp-block-table"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td></td><td>Table with empty cells.</td></tr></tbody></table>
<!-- /wp:table -->

<!-- wp:heading -->
<h2>Quote</h2>
<!-- /wp:heading -->
Expand Down

0 comments on commit 7de6ef4

Please sign in to comment.