Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste: preserve empty table cells #14137

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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