Skip to content

Commit

Permalink
fix: Filter null values from slateTable cells
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli authored and ericof committed Nov 9, 2022
1 parent 7c5d08c commit cedd0dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/converters/slate.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ const slateTableBlock = (elem) => {
const cells = [];
for (const cell of tchild.children) {
const cellType = cell.tagName === 'TD' ? 'data' : 'header';
const cellValue = Array.from(cell.childNodes).map(deserialize);
const cellValue = Array.from(cell.childNodes)
.map(deserialize)
.filter((x) => x);
cells.push(createCell(cellType, cellValue));
}
rows.push({ key: getId(), cells });
Expand Down
19 changes: 19 additions & 0 deletions src/converters/slate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ describe('slateTableBlock processing a simple table', () => {
});
});

describe('slateTableBlock processing a table with whitespace', () => {
const elem = elementFromString(
'<table><tr><td>A value<br>&nbsp;</td></tr></table>',
);

test('will remove the whitespace', () => {
const result = slateTableBlock(elem);
const rows = result.table.rows;
expect(rows).toHaveLength(1);
const cells = rows[0].cells;
expect(cells).toHaveLength(1);
const cell = cells[0];
expect(cell.value).toEqual([
{ type: 'p', children: [{ text: 'A value' }] },
{ type: 'p', children: [{ text: '\n' }] },
]);
});
});

describe('slateTableBlock processing a table with a link', () => {
const elem = elementFromString(
'<table><tr><td><a href="https://plone.org">Plone</a></td></tr></table>',
Expand Down

0 comments on commit cedd0dd

Please sign in to comment.