Skip to content

Commit

Permalink
refactor: separate file for TableHeadRow
Browse files Browse the repository at this point in the history
Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Mar 16, 2022
1 parent 8709a3c commit 406f6fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
32 changes: 2 additions & 30 deletions src/nodes/TableHead.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
import { Node, mergeAttributes } from '@tiptap/core'

const tableHeadRow = Node.create({
name: 'tableHeadRow',
content: 'tableHeader*',
tableRole: 'headRow',

addOptions() {
return {
HTMLAttributes: {},
}
},

parseHTML() {
return [
{ tag: 'tr' },
]
},

renderHTML({ HTMLAttributes }) {
return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},

toMarkdown(state, node) {
state.write('|')
state.renderInline(node)
state.ensureNewLine()
},

})
import TableHeadRow from './TableHeadRow'

export default Node.create({
name: 'tableHead',
Expand All @@ -42,7 +14,7 @@ export default Node.create({

addExtensions() {
return [
tableHeadRow,
TableHeadRow,
]
},

Expand Down
30 changes: 30 additions & 0 deletions src/nodes/TableHeadRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Node, mergeAttributes } from '@tiptap/core'

export default Node.create({
name: 'tableHeadRow',
content: 'tableHeader*',
tableRole: 'headRow',

addOptions() {
return {
HTMLAttributes: {},
}
},

parseHTML() {
return [
{ tag: 'tr' },
]
},

renderHTML({ HTMLAttributes }) {
return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},

toMarkdown(state, node) {
state.write('|')
state.renderInline(node)
state.ensureNewLine()
},

})
2 changes: 1 addition & 1 deletion src/tests/tables.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Table', () => {
test('serialize from editor', () => {
const tiptap = editorWithContent(markdownit.render(input))
const serializer = createMarkdownSerializer(tiptap.schema)
expect(serializer.serialize(tiptap.state.doc)).toBe(input.replace(/\n$/, ''))
expect(serializer.serialize(tiptap.state.doc)).toBe(input)
})

test('handle html table with other structure', () => {
Expand Down

0 comments on commit 406f6fb

Please sign in to comment.