File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed
packages/core/src/blocks/TableBlockContent Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -34,16 +34,45 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
3434 ] ;
3535 } ,
3636
37- renderHTML ( { HTMLAttributes } ) {
38- return createDefaultBlockDOMOutputSpec (
37+ renderHTML ( { node , HTMLAttributes } ) {
38+ const domOutputSpec = createDefaultBlockDOMOutputSpec (
3939 this . name ,
4040 "table" ,
4141 {
42- ...( this . options . domAttributes ?. blockContent || { } ) ,
42+ ...( this . options . domAttributes ?. blockContent || { fesfes : "fesfes" } ) ,
4343 ...HTMLAttributes ,
4444 } ,
4545 this . options . domAttributes ?. inlineContent || { } ,
4646 ) ;
47+
48+ // Need to manually add column widths.
49+ const cols : HTMLTableColElement [ ] = [ ] ;
50+ for ( const tableCell of node . children [ 0 ] . children ) {
51+ const colWidths : null | ( number | undefined ) [ ] =
52+ tableCell . attrs [ "colwidth" ] ;
53+
54+ if ( colWidths ) {
55+ for ( const colWidth of tableCell . attrs [ "colwidth" ] ) {
56+ const col = document . createElement ( "col" ) ;
57+ if ( colWidth ) {
58+ col . style = `width: ${ colWidth } px` ;
59+ }
60+
61+ cols . push ( col ) ;
62+ }
63+ } else {
64+ cols . push ( document . createElement ( "col" ) ) ;
65+ }
66+ }
67+
68+ const colGroup = document . createElement ( "colgroup" ) ;
69+ for ( const col of cols ) {
70+ colGroup . appendChild ( col ) ;
71+ }
72+
73+ domOutputSpec . dom . firstChild ?. appendChild ( colGroup ) ;
74+
75+ return domOutputSpec ;
4776 } ,
4877
4978 // This node view is needed for the `columnResizing` plugin. By default, the
You can’t perform that action at this time.
0 commit comments