nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jugglerchris/rust-html2text
Pull request #135 (2024-03-03 09:31:34)

Treat max-height: 0 as display: none.
Addresses #134 .



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a41616..f1aac4a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,11 @@ Possible log types:
 - `[fixed]` for any bug fixes.
 - `[security]` to invite users to upgrade in case of vulnerabilities.
 
+### 0.12.3
+
+- [changed] Treat `max-height: 0` as if it's `display: none` when CSS is enabled.
+  This helps with a hack some e-mail senders use for e-mail previews.  (thanks tkapias)
+
 ### 0.12.2
 
 - [changed] Bump version of lightningcss dependency to fix build failures.
diff --git a/Cargo.toml b/Cargo.toml
index 405cecd..bf545d8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "html2text"
-version = "0.12.2"
+version = "0.12.3"
 authors = ["Chris Emerson <github@mail.nosreme.org>"]
 description = "Render HTML as plain text."
 repository = "https://github.com/jugglerchris/rust-html2text/"
diff --git a/src/css.rs b/src/css.rs
index 51c2579..1303d98 100644
--- a/src/css.rs
+++ b/src/css.rs
@@ -238,6 +238,20 @@ fn styles_from_properties(decls: &DeclarationBlock<'_>) -> Vec<Style> {
                 }
                 styles.push(Style::BgColour(color.clone()));
             }
+            Property::MaxHeight(height) => {
+                use lightningcss::properties::size::MaxSize::*;
+                use lightningcss::values::percentage::DimensionPercentage::*;
+                dbg!(&height);
+                match height {
+                    LengthPercentage(Dimension(dim)) => {
+                        // Treat max-height: 0 the same as display: none.
+                        if Some(0.0) == dim.to_px() {
+                            styles.push(Style::DisplayNone);
+                        }
+                    }
+                    _ => (),
+                }
+            }
             Property::Display(disp) => {
                 if let display::Display::Keyword(DisplayKeyword::None) = disp {
                     styles.push(Style::DisplayNone);


Test patch:
diff --git a/src/tests.rs b/src/tests.rs
index 6835139..7ffe8cb 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -2327,4 +2327,16 @@ text
                   "H\ne\nl\nl\no\n*<W></W>\n<W>t</W>\n<W>h</W>\n<W>e</W>\n<W>r</W>\n<W>e</W>\n*\nb\no\no\n",
                   1);
     }
+
+    #[test]
+    fn test_height_0() {
+        test_html_css(
+            br#"
+        <div style="max-height: 0">This should be hidden</div>
+        <p>Hello</p>"#,
+            r#"Hello
+"#,
+            20,
+        );
+    }
 }