tiptap/packages/extension-table-header/src/table-header.ts

54 lines
951 B
TypeScript
Raw Normal View History

2021-01-22 07:16:58 +08:00
import { Node, mergeAttributes } from '@tiptap/core'
export interface TableHeaderOptions {
2021-04-21 15:43:31 +08:00
HTMLAttributes: Record<string, any>,
2021-01-22 07:16:58 +08:00
}
2021-02-11 01:25:08 +08:00
export const TableHeader = Node.create<TableHeaderOptions>({
name: 'tableHeader',
2021-01-22 07:16:58 +08:00
addOptions() {
return {
HTMLAttributes: {},
}
2021-01-22 07:16:58 +08:00
},
content: 'block+',
addAttributes() {
return {
colspan: {
default: 1,
},
rowspan: {
default: 1,
},
colwidth: {
default: null,
2021-03-29 02:19:17 +08:00
parseHTML: element => {
const colwidth = element.getAttribute('colwidth')
const value = colwidth
? [parseInt(colwidth, 10)]
: null
return value
2021-03-29 02:19:17 +08:00
},
2021-01-22 07:16:58 +08:00
},
}
},
tableRole: 'header_cell',
isolating: true,
parseHTML() {
2021-01-24 05:48:34 +08:00
return [
{ tag: 'th' },
]
2021-01-22 07:16:58 +08:00
},
renderHTML({ HTMLAttributes }) {
return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},
})