mirror of
https://github.com/typst/typst
synced 2025-08-10 05:07:55 +08:00
Simplify header/footer logic.
This commit is contained in:
parent
bb950275cd
commit
7da7e28afc
@ -276,28 +276,19 @@ impl Show for Packed<TableElem> {
|
|||||||
});
|
});
|
||||||
let mut rows: Vec<_> = rows.collect();
|
let mut rows: Vec<_> = rows.collect();
|
||||||
|
|
||||||
let footer_start =
|
let footer = grid.footer.map(|ft| {
|
||||||
grid.footer.map_or(rows.len(), |footer| footer.unwrap().start);
|
elem(tag::tfoot, Content::sequence(rows.drain(ft.unwrap().start..)))
|
||||||
let header_end = grid.header.map_or(0, |footer| footer.unwrap().end);
|
});
|
||||||
let footer: Vec<_> = rows.drain(footer_start..).collect();
|
let header = grid.header.map(|hd| {
|
||||||
let body: Vec<_> = rows.drain(header_end..).collect();
|
elem(tag::thead, Content::sequence(rows.drain(..hd.unwrap().end)))
|
||||||
let header = rows;
|
});
|
||||||
|
|
||||||
let mut content = Vec::new();
|
let mut body = Content::sequence(rows);
|
||||||
|
if header.is_some() || footer.is_some() {
|
||||||
let only_body = header.is_empty() && footer.is_empty();
|
body = elem(tag::tbody, body);
|
||||||
if !header.is_empty() {
|
|
||||||
content.push(elem(tag::thead, Content::sequence(header)));
|
|
||||||
}
|
|
||||||
if only_body {
|
|
||||||
content = body;
|
|
||||||
} else {
|
|
||||||
content.push(elem(tag::tbody, Content::sequence(body)));
|
|
||||||
}
|
|
||||||
if !footer.is_empty() {
|
|
||||||
content.push(elem(tag::tfoot, Content::sequence(footer)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let content = header.into_iter().chain(core::iter::once(body)).chain(footer);
|
||||||
elem(tag::table, Content::sequence(content))
|
elem(tag::table, Content::sequence(content))
|
||||||
} else {
|
} else {
|
||||||
BlockElem::multi_layouter(self.clone(), engine.routines.layout_table).pack()
|
BlockElem::multi_layouter(self.clone(), engine.routines.layout_table).pack()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user