diff --git a/crates/html/src/doc/builder.rs b/crates/html/src/doc/builder.rs index dce6a5957..fbce35a2a 100644 --- a/crates/html/src/doc/builder.rs +++ b/crates/html/src/doc/builder.rs @@ -71,10 +71,8 @@ impl TableB { if let Some(rows) = self.rows.get_mut(self.group_start..end) { let mut remaining = 0u32; for row in rows.iter_mut().rev() { - if !row.is_empty() { - remaining += 1; - } - // Resolve zero spans before expanding the table's covered cells. + // Covered cells are inserted using the original row indices, including empty rows. + remaining += 1; for cell in row.iter_mut().filter(|cell| cell.rowspan == 0) { cell.rowspan = remaining.clamp(1, 1000); } diff --git a/crates/html/src/doc/tests.rs b/crates/html/src/doc/tests.rs index 7587e5891..1a2da811f 100644 --- a/crates/html/src/doc/tests.rs +++ b/crates/html/src/doc/tests.rs @@ -2070,3 +2070,27 @@ fn zero_rowspan_stops_at_the_row_group_boundary() { assert_eq!(table.rows[2].len(), 2, "{boundary}: D and E retain their columns"); } } + +#[test] +fn zero_rowspan_covers_an_empty_middle_row() { + let flow = parse("
AB
C
"); + let FBlock::Table(table) = &flow.blocks[0] else { panic!("expected a table") }; + + assert_eq!(table.rows.len(), 3); + assert_eq!(table.rows[0][0].rowspan, 3); + assert!(table.rows[1][0].covered); + assert!(table.rows[2][0].covered); + assert_eq!(table.rows[2][1].text(), "C"); +} + +#[test] +fn zero_rowspan_covers_an_empty_trailing_row() { + let flow = parse("
AB
C
D
"); + let FBlock::Table(table) = &flow.blocks[0] else { panic!("expected a table") }; + + assert_eq!(table.rows[0][0].rowspan, 3); + assert_eq!(table.rows.len(), 4); + assert!(table.rows[2][0].covered); + assert!(!table.rows[3][0].covered); + assert_eq!(table.rows[3][0].text(), "D"); +}