Skip to content

Commit 8e40758

Browse files
committed
fix(table): Allow all block elements as table children
Also add tests for tables with complex nested structures in their cells. Signed-off-by: Jonas <[email protected]>
1 parent 2bce823 commit 8e40758

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/nodes/Table/TableCell.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { Fragment } from '@tiptap/pm/model'
99
import { Plugin } from '@tiptap/pm/state'
1010

1111
export default TableCell.extend({
12-
content: '(paragraph|list|codeBlock|image)+',
12+
// content: 'block+',
13+
// All block elements except blockquote as that one causes issues for now.
14+
// Blockquote as nested child (e.g. inside a list) is no problem.
15+
content: '(paragraph|list|codeBlock|image|callout|details|horizontalRule)+',
1316

1417
toMarkdown() {},
1518

src/tests/nodes/Table.spec.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,54 @@ describe('Table extension', () => {
4444
expect(rendered).toBe(output)
4545
})
4646

47-
it('markdown table is preserved through editor', () => {
47+
it('simple md table is preserved through editor', () => {
4848
expect(markdownThroughEditor('a|b\n-|-\n1|2\n')).toBe(
4949
'| a | b |\n|---|---|\n| 1 | 2 |\n',
5050
)
51+
})
5152

52-
const complexTable = `
53+
it('complex md table with alignment, nested list, image and code block is preserved through editor', () => {
54+
const table = `
5355
| # | header1 | header2 |
5456
|--:|------------------:|---------------|
5557
| 1 | list: | code: | \\
5658
| | | | \\
5759
| | * item1 | \`\`\`js | \\
58-
| | * item2 | const x = '1' | \\
60+
| | * item2 | const x = '1' | \\
5961
| | | \`\`\` | \\
6062
| | ![alt](/test.png) | |
6163
| 2 | cell3 | cell4 |
6264
| 3 | | cell5 |
6365
`.trimStart()
64-
expect(markdownThroughEditor(complexTable)).toBe(complexTable)
66+
67+
expect(markdownThroughEditor(table)).toBe(table)
68+
})
69+
70+
it('complex md table with callout, hr, blockquote and details in nested list is preserved through editor', () => {
71+
const table = `
72+
| nested list1 | nested list 2 |
73+
|-----------------------|----------------------------------|
74+
| 1. first with callout | 1. first with blockquote | \\
75+
| | | \\
76+
| ::: info | > - quoted list item1 | \\
77+
| info | > - quoted list item2 | \\
78+
| | 1. with image | \\
79+
| ::: | | \\
80+
| 1. item2 | ![a](i.png) | \\
81+
| 2. second | 2. summary | \\
82+
| | | \\
83+
| --- | <details> | \\
84+
| | <summary>summary</summary> | \\
85+
| ::: warn | > * quoted list item | \\
86+
| warn | | \\
87+
| | </details> | \\
88+
| ::: | |
89+
| * [ ] task list item1 | | \\
90+
| * [x] task list item2 | |
91+
| > quote | |
92+
`.trimStart()
93+
94+
expect(markdownThroughEditor(table)).toBe(table)
6595
})
6696

6797
test('Load into editor', ({ editor }) => {

0 commit comments

Comments
 (0)