mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-22 18:41:27 +01:00
Count empty rows when resolving HTML zero row spans
This commit is contained in:
1 parent
da4c3caba5
commit
d6e13ee891
2 files changed
+26
-4
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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("<table><tbody><tr><td rowspan=0>A<td>B</tr><tr></tr><tr><td>C</tr></tbody></table>");
|
||||
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("<table><tbody><tr><td rowspan=0>A<td>B</tr><tr><td>C</tr><tr></tr></tbody><tbody><tr><td>D</tr></tbody></table>");
|
||||
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");
|
||||
}
|
||||
Reference in new issue
Block a user