mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
Merge pull request #1947 from keithcsqueensu/flow-header-row-default
flow: a table with no style has no header row from the default look
This commit is contained in:
2 files changed
+30
-1
No files matched your search
@@ -1101,7 +1101,10 @@ fn flow_table(doc: &Document, t: &Table, depth: usize, tracked: FlowOpts) -> FTa
|
||||
let ncols =
|
||||
t.rows.iter().map(|r| r.first_grid() + r.cells.iter().map(|c| c.span()).sum::<usize>() + r.grid_after()).max().unwrap_or(0).max(t.grid.len());
|
||||
for (ri, r) in t.rows.iter().enumerate() {
|
||||
let header = r.props.header || (ri == 0 && t.props.look.header_row && t.rows.len() > 1);
|
||||
// The look's header row is an option of the table's style (`w:tblLook/@w:firstRow`): with
|
||||
// no table style there is nothing to apply, so the first row stays an ordinary row, as in
|
||||
// Word. Only Repeat as header row makes it one then.
|
||||
let header = r.props.header || (ri == 0 && style.is_some() && t.props.look.header_row && t.rows.len() > 1);
|
||||
let mut cells = Vec::new();
|
||||
for (ci, c) in r.cells.iter().enumerate() {
|
||||
let styled = if bake { styled_cell(t, style.as_ref(), (ri, ci), ncols) } else { None };
|
||||
|
||||
@@ -80,6 +80,32 @@ mod tests {
|
||||
assert!(kept);
|
||||
}
|
||||
|
||||
/// The default look's header row is an option of the table style: a table with no style (or a
|
||||
/// style the document doesn't have) has an ordinary first row, so RTF doesn't bold it or
|
||||
/// repeat it on each page, and HTML doesn't make it `th`. Repeat as header row still does.
|
||||
#[test]
|
||||
fn look_header_row_needs_a_table_style() {
|
||||
use craft_wordmodel::{Block, Document, table::Table};
|
||||
let first_row_header = |style: Option<&str>, repeat: bool| {
|
||||
let mut t = Table::new(2, 2, 200.0);
|
||||
t.props.style = style.map(str::to_string);
|
||||
assert!(t.props.look.header_row, "the default look has a header row");
|
||||
if let Some(r) = t.rows.first_mut() {
|
||||
r.props.header = repeat;
|
||||
}
|
||||
let mut doc = Document::new();
|
||||
doc.body = vec![std::sync::Arc::new(Block::Table(t))];
|
||||
let flow = from_doc(&doc);
|
||||
let Some(FBlock::Table(ft)) = flow.blocks.iter().find(|b| matches!(b, FBlock::Table(_))) else { panic!("no table in {:?}", flow.blocks) };
|
||||
assert!(ft.rows.get(1).is_some_and(|r| r.iter().all(|c| !c.header)), "the second row is never a header");
|
||||
ft.rows.first().is_some_and(|r| r.iter().all(|c| c.header))
|
||||
};
|
||||
assert!(first_row_header(Some("TableGrid"), false), "a table style applies the look's header row");
|
||||
assert!(!first_row_header(None, false), "no style, no header row");
|
||||
assert!(!first_row_header(Some("NoSuchStyle"), false), "a missing style applies nothing");
|
||||
assert!(first_row_header(None, true), "Repeat as header row");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percent_decode_requires_hex_digits() {
|
||||
assert_eq!(percent_decode("%+A"), b"%+A".to_vec());
|
||||
|
||||
Reference in new issue
Block a user