From: Scott Worley Date: Sat, 5 Oct 2024 01:47:20 +0000 (-0700) Subject: Don't color the background of cells that contain only '×'s X-Git-Tag: v0.5.0~3 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/a1a4b3c8f14d52f8b85e7fd72b5c430fe4407483?ds=sidebyside Don't color the background of cells that contain only '×'s --- diff --git a/Changelog b/Changelog index cb3b4c5..5963bc8 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ - `!label col:new label` to substitute a different label for a column - Use Unicode tally marks to coalesce multiple no-colon entries (If you need a font for these, I recommend "BabelStone Han") +- Don't color the background of cells that contain only '×'s ## [0.4.0] - 2024-10-03 - Read column threshold from `!col_threshold ` in input diff --git a/src/lib.rs b/src/lib.rs index 84cb336..859b3c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,7 +315,14 @@ fn render_cell(col: &str, row: &mut Row) -> HTML { let row_label = HTML::escape(row.label.as_ref()); let col_label = HTML::escape(col); let instances: Option<&Vec>> = row.entries.get(col); - let class = HTML::from(if instances.is_none() { "" } else { "yes" }); + let is_empty = match instances { + None => true, + Some(is) => is.iter().all(|ins| match ins { + None => false, + Some(content) => content == "×", + }), + }; + let class = HTML::from(if is_empty { "" } else { "yes" }); let contents = match instances { None => HTML::from(""), Some(is) => render_instances(is), @@ -756,6 +763,18 @@ mod tests { r#"5 𝍷"# ) ); + assert_eq!( + render_cell( + "foo", + &mut Row { + label: "nope".to_owned(), + entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]), + } + ), + HTML::from( + r#"×"# + ) + ); assert_eq!( render_cell( "heart",