]> git.scottworley.com Git - tablify/commitdiff
Don't color the background of cells that contain only '×'s
authorScott Worley <scottworley@scottworley.com>
Sat, 5 Oct 2024 01:47:20 +0000 (18:47 -0700)
committerScott Worley <scottworley@scottworley.com>
Sat, 5 Oct 2024 01:47:20 +0000 (18:47 -0700)
Changelog
src/lib.rs

index cb3b4c5c337d2c379fdaaeed053dd76ab1619fbc..5963bc857468dbdedce7287f6209af47420976c1 100644 (file)
--- 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 <N>` in input
index 84cb336301e83f47b6e13bf4b484c41dca1322b5..859b3c19157d11b1e003165bbc7a72249641fc62 100644 (file)
@@ -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<Option<String>>> = 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#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 𝍷</td>"#
             )
         );
+        assert_eq!(
+            render_cell(
+                "foo",
+                &mut Row {
+                    label: "nope".to_owned(),
+                    entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]),
+                }
+            ),
+            HTML::from(
+                r#"<td class="" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">×</td>"#
+            )
+        );
         assert_eq!(
             render_cell(
                 "heart",