Hello, I modified the code of prosemirror-tables to support table sections: thead, tbody, tfoot (and caption).
My goal is supporting the table structure of Pandoc.
I’m going to publish it on github, but I have two problems:
-
choosing an appropriate name:
prosemirror-tables-sections
,prosemirror-tables-plus
, something else? -
how to implement the colgroup DOM element
The code seems to work fine, I’ve adapted the tests and they all pass. I’m getting rid of the custom TableView of prosemirror-tables, because this is the new schema:
const schema = {
table: {
// content: 'table_row+',
content: 'table_caption? table_head? table_body+ table_foot?',
tableRole: 'table',
isolating: true,
group: options.tableGroup,
attrs: tableAttrs,
parseDOM: [{ tag: 'table' }],
toDOM() {
// return ['table', ['tbody', 0]];
return ['table']
},
},
table_caption: {
content: 'block+',
tableRole: 'caption',
isolating: true,
parseDOM: [{ tag: 'caption' }],
toDOM() {
return ['caption', 0];
},
},
table_head: {
content: 'table_row+',
tableRole: 'table_section',
isolating: true,
parseDOM: [{ tag: 'thead' }],
toDOM() {
return ['thead', 0];
},
},
table_foot: {
content: 'table_row+',
tableRole: 'table_section',
isolating: true,
parseDOM: [{ tag: 'tfoot' }],
toDOM() {
return ['tfoot', 0];
},
},
table_body: {
content: 'table_row+',
tableRole: 'table_section',
isolating: true,
parseDOM: [{ tag: 'tbody' }],
toDOM() {
return ['tbody', 0];
},
},
table_row: {
content: '(table_cell | table_header)*',
tableRole: 'row',
parseDOM: [{ tag: 'tr' }],
toDOM() {
return ['tr', 0];
},
},
table_cell: {
content: options.cellContent,
attrs: cellAttrs,
tableRole: 'cell',
isolating: true,
parseDOM: [
{ tag: 'td', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
],
toDOM(node) {
return ['td', setCellAttrs(node, extraAttrs), 0];
},
},
table_header: {
content: options.cellContent,
attrs: cellAttrs,
tableRole: 'header_cell',
isolating: true,
parseDOM: [
{ tag: 'th', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
],
toDOM(node) {
return ['th', setCellAttrs(node, extraAttrs), 0];
},
},
};
TableView created and managed the colgroup
element. Since I can’t write something like this for the table
node:
toDOM() {
// return ['table', ['tbody', 0]];
return ['table', ['colgroup'], 0]
},
A solution could be setting the content
of a table to:
'colgroup table_caption? table_head? table_body+ table_foot?'
where colgroup
would be an atomic element to be created automatically.
Is there a better solution?