From df1deb6c36b42e4dee065742e5791afe95f04f5d Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 16 Mar 2022 11:07:31 +0100 Subject: fix: preserve td and th attributes Prosemirror expects colspan, rowspan and the like to calculate the table layout. Signed-off-by: Max --- src/nodes/TableCell.js | 4 --- src/nodes/TableHeadRow.js | 26 +++++-------------- src/nodes/TableHeader.js | 4 --- src/nodes/TableRow.js | 3 --- src/tests/fixtures/tables/basic.out.html | 8 +++--- src/tests/fixtures/tables/handbook.out.html | 40 ++++++++++++++--------------- 6 files changed, 31 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/nodes/TableCell.js b/src/nodes/TableCell.js index 82fa666b3..a8ce69234 100644 --- a/src/nodes/TableCell.js +++ b/src/nodes/TableCell.js @@ -3,10 +3,6 @@ import { TableCell } from '@tiptap/extension-table-cell' export default TableCell.extend({ content: 'inline*', - addAttributes() { - return {} - }, - toMarkdown(state, node) { state.write(' ') state.renderInline(node) diff --git a/src/nodes/TableHeadRow.js b/src/nodes/TableHeadRow.js index 8845ae462..ea13c9b2e 100644 --- a/src/nodes/TableHeadRow.js +++ b/src/nodes/TableHeadRow.js @@ -1,25 +1,8 @@ -import { Node, mergeAttributes } from '@tiptap/core' +import TableRow from './TableRow' -export default Node.create({ +export default TableRow.extend({ name: 'tableHeadRow', content: 'tableHeader*', - tableRole: 'row', - - addOptions() { - return { - HTMLAttributes: {}, - } - }, - - parseHTML() { - return [ - { tag: 'tr' }, - ] - }, - - renderHTML({ HTMLAttributes }) { - return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] - }, toMarkdown(state, node) { state.write('|') @@ -33,4 +16,9 @@ export default Node.create({ state.ensureNewLine() }, + parseHTML() { + return [ + { tag: 'tr', priority: 70 }, + ] + }, }) diff --git a/src/nodes/TableHeader.js b/src/nodes/TableHeader.js index b08f5c609..db9224742 100644 --- a/src/nodes/TableHeader.js +++ b/src/nodes/TableHeader.js @@ -3,10 +3,6 @@ import { TableHeader } from '@tiptap/extension-table-header' export default TableHeader.extend({ content: 'inline*', - addAttributes() { - return {} - }, - toMarkdown(state, node) { state.write(' ') state.renderInline(node) diff --git a/src/nodes/TableRow.js b/src/nodes/TableRow.js index 61e0b982a..b7343eb9a 100644 --- a/src/nodes/TableRow.js +++ b/src/nodes/TableRow.js @@ -2,9 +2,6 @@ import { TableRow } from '@tiptap/extension-table-row' export default TableRow.extend({ content: 'tableCell*', - addAttributes() { - return {} - }, toMarkdown(state, node) { state.write('|') diff --git a/src/tests/fixtures/tables/basic.out.html b/src/tests/fixtures/tables/basic.out.html index c0b517180..d92b28d0f 100644 --- a/src/tests/fixtures/tables/basic.out.html +++ b/src/tests/fixtures/tables/basic.out.html @@ -1,10 +1,10 @@ - - + + - - + +
headingother headingheadingother heading
cellother cellcellother cell
diff --git a/src/tests/fixtures/tables/handbook.out.html b/src/tests/fixtures/tables/handbook.out.html index 4d8afad4f..32a29d132 100644 --- a/src/tests/fixtures/tables/handbook.out.html +++ b/src/tests/fixtures/tables/handbook.out.html @@ -1,30 +1,30 @@ - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + +
Heading 0Heading 1Heading 2Heading 3Heading 4Heading 0Heading 1Heading 2Heading 3Heading 4
LetterabcdLetterabcd
Number1234Number1234
Square14916Square14916
-- cgit v1.2.3