Skip to content

Commit

Permalink
fix: Don't turn text nodes that are children of table cells into para…
Browse files Browse the repository at this point in the history
…graphs
  • Loading branch information
davisagli committed Nov 28, 2022
1 parent 9a69472 commit e96e2c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/converters/slate.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const deserialize = (el) => {
const createCell = (type, rawValue) => {
const value = rawValue.map(function (el) {
if (typeof el === 'string') {
return jsx('element', { type: 'p' }, el);
return { text: el };
} else {
return el;
}
Expand Down
29 changes: 21 additions & 8 deletions src/converters/slate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ describe('slateTableBlock processing a simple table', () => {
expect(rows[0].cells[0].type).toBe('data');
expect(rows[0].cells[0].value).toHaveLength(1);
const value = rows[0].cells[0].value[0];
expect(value['type']).toBe('p');
expect(value['children'][0]['text']).toBe('A value');
expect(value['text']).toBe('A value');
});
});

Expand All @@ -537,10 +536,7 @@ describe('slateTableBlock processing a table with whitespace', () => {
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' }] },
]);
expect(cell.value).toEqual([{ text: 'A value' }, { text: '\n' }]);
});
});

Expand Down Expand Up @@ -591,8 +587,7 @@ describe('slateTableBlock processing a table with a link', () => {
const result = slateTableBlock(elem);
const rows = result.table.rows;
let value = rows[0].cells[0].value[0];
expect(value['type']).toBe('p');
expect(value['children'][0]['text']).toBe('Plone ');
expect(value['text']).toBe('Plone ');
});

test('second value is the link', () => {
Expand Down Expand Up @@ -624,4 +619,22 @@ describe('slateTableBlock processing a table with a link', () => {
expect(valueElement['children'][0]['text']).toBe('');
});
});

describe('slateTableBlock processing a table with text + sup', () => {
const elem = elementFromString(
'<table><tr><td>10<sup>2</sup></td></tr></table>',
);

test('will keep sup inline', () => {
const result = slateTableBlock(elem);
const cell = result.table.rows[0].cells[0];
expect(cell.value).toEqual([
{ text: '10' },
{
type: 'sup',
children: [{ text: '2' }],
},
]);
});
});
});

0 comments on commit e96e2c3

Please sign in to comment.