From 5292c5b198aaf39f6666fd9164d7fa2e1653b495 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Fri, 16 May 2025 20:01:17 -0300 Subject: [PATCH] update html code for multiple footers todo: test --- crates/typst-library/src/model/table.rs | 33 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/typst-library/src/model/table.rs b/crates/typst-library/src/model/table.rs index dcc77b0dc..367d3e66f 100644 --- a/crates/typst-library/src/model/table.rs +++ b/crates/typst-library/src/model/table.rs @@ -292,12 +292,33 @@ fn show_cellgrid_html(grid: CellGrid, styles: StyleChain) -> Content { elem(tag::tr, Content::sequence(row)) }; - // TODO(subfooters): similarly to headers, take consecutive footers from - // the end for 'tfoot'. - let footer = grid.footer.map(|ft| { - let rows = rows.drain(ft.start..); - elem(tag::tfoot, Content::sequence(rows.map(|row| tr(tag::td, row)))) - }); + // Store all consecutive headers at the start in 'tfoot'. All remaining + // headers are just normal rows across the table body. (There doesn't + // appear to be an equivalent of 'th' for footers in HTML.) + // TODO: test + let footer = { + let mut consecutive_footer_start = grid.footers.len(); + let footers_at_end = grid + .footers + .iter() + .rev() + .take_while(|ft| { + let is_consecutive = ft.end == consecutive_footer_start; + consecutive_footer_start = ft.start; + + is_consecutive + }) + .count(); + + if footers_at_end > 0 { + let last_mid_table_footer = grid.footers.len() - footers_at_end; + let rows = rows.drain(last_mid_table_footer..); + + Some(elem(tag::tfoot, Content::sequence(rows.map(|row| tr(tag::td, row))))) + } else { + None + } + }; // Store all consecutive headers at the start in 'thead'. All remaining // headers are just 'th' rows across the table body.