@@ -93,12 +93,9 @@ export const tableProcessor: ElementProcessor<HTMLTableElement> = (
9393
9494 stackFormat ( context , { paragraph : 'shallowClone' , segment : 'shallowClone' } , ( ) => {
9595 const parent = tr . parentElement ;
96- const parentTag = parent ?. tagName ;
96+ const isInTableSection = parent && getIsInTableSection ( parent ) ;
9797
98- if (
99- parent &&
100- ( parentTag == 'TBODY' || parentTag == 'THEAD' || parentTag == 'TFOOT' )
101- ) {
98+ if ( isInTableSection ) {
10299 // If there is TBODY around TR, retrieve format from TBODY first, in case some format are declared there
103100 parseFormat (
104101 parent ,
@@ -197,10 +194,21 @@ export const tableProcessor: ElementProcessor<HTMLTableElement> = (
197194
198195 for (
199196 let colSpan = 1 ;
200- colSpan <= td . colSpan ;
197+ colSpan <= ( td . colSpan == 0 ? 1 : td . colSpan ) ;
201198 colSpan ++ , targetCol ++
202199 ) {
203- for ( let rowSpan = 1 ; rowSpan <= td . rowSpan ; rowSpan ++ ) {
200+ for (
201+ let rowSpan = 1 ;
202+ // RowSpan of 0 means it should span to the end of the table
203+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/td#rowspan
204+ rowSpan <=
205+ ( td . rowSpan == 0
206+ ? isInTableSection
207+ ? translateRowSpanZero ( parent , td )
208+ : 1
209+ : td . rowSpan ) ;
210+ rowSpan ++
211+ ) {
204212 const hasTd = colSpan == 1 && rowSpan == 1 ;
205213 const cell = createTableCell (
206214 colSpan > 1 ,
@@ -282,6 +290,26 @@ export const tableProcessor: ElementProcessor<HTMLTableElement> = (
282290 ) ;
283291} ;
284292
293+ function translateRowSpanZero ( parent : HTMLTableSectionElement , td : HTMLTableCellElement ) {
294+ const amountOfRows = parent . rows . length ;
295+
296+ let tdIndex = - 1 ;
297+ for ( let i = 0 ; i < parent . rows . length ; i ++ ) {
298+ const row = parent . rows [ i ] ;
299+ for ( let j = 0 ; j < row . cells . length ; j ++ ) {
300+ if ( row . cells [ j ] === td ) {
301+ tdIndex = i ;
302+ break ;
303+ }
304+ }
305+ if ( tdIndex !== - 1 ) {
306+ break ;
307+ }
308+ }
309+
310+ return amountOfRows - tdIndex ;
311+ }
312+
285313function calcSizes ( positions : ( number | undefined ) [ ] ) : number [ ] {
286314 const result : number [ ] = [ ] ;
287315 let lastPos = 0 ;
@@ -368,3 +396,11 @@ function shouldRecalculateTableSize(table: HTMLTableElement, context: DomToModel
368396 return false ;
369397 }
370398}
399+
400+ function getIsInTableSection ( element : HTMLElement ) : element is HTMLTableSectionElement {
401+ return (
402+ isElementOfType ( element , 'tbody' ) ||
403+ isElementOfType ( element , 'thead' ) ||
404+ isElementOfType ( element , 'tfoot' )
405+ ) ;
406+ }
0 commit comments