From c12cdaca08a02cb78aed7e6ba75e33dfac9d3cc5 Mon Sep 17 00:00:00 2001 From: Evgeny Arshinov Date: Sun, 31 Oct 2021 17:08:09 +0300 Subject: [PATCH 1/4] test --- premailer/tests/test_merge_style.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/premailer/tests/test_merge_style.py b/premailer/tests/test_merge_style.py index 4b13e7e..72e7b9e 100644 --- a/premailer/tests/test_merge_style.py +++ b/premailer/tests/test_merge_style.py @@ -15,3 +15,14 @@ def test_inline_invalid_syntax(self): # Invalid syntax does not raise inline = "{color:pink} :hover{color:purple} :active{color:red}" merge_styles(inline, [], []) + + def test_constituent_styles(self): + # "constituent": `margin-bottom` is a constituent style of `margin` + new_styles = [[("margin", "5px"), ("margin-bottom", "10px")]] + classes = [""] + inline_style = "margin: 0" + csstext = merge_styles(inline_style, new_styles, classes) + self.assertEqual( + # ideally premailer could eliminate margin-bottom altogether + [("margin-bottom", "5px"), ("margin", "0")], csstext_to_pairs(csstext) + ) From 8d9e606432c83418ec3566b54a9027b974d3ef72 Mon Sep 17 00:00:00 2001 From: Evgeny Arshinov Date: Sun, 31 Oct 2021 17:08:13 +0300 Subject: [PATCH 2/4] fix --- premailer/merge_style.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/premailer/merge_style.py b/premailer/merge_style.py index 62d4a9d..5fc29d9 100644 --- a/premailer/merge_style.py +++ b/premailer/merge_style.py @@ -61,10 +61,13 @@ def merge_styles(inline_style, new_styles, classes, remove_unset_properties=Fals # keep always the old inline style if inline_style: + normal_styles_dict = styles[""] # inline should be a declaration list as I understand # ie property-name:property-value;... for k, v in csstext_to_pairs(inline_style): - styles[""][k] = v + if k in normal_styles_dict: + del normal_styles_dict[k] + normal_styles_dict[k] = v normal_styles = [] pseudo_styles = [] From 935bb2c99bbda0fdfce58e75b06557f703d17d82 Mon Sep 17 00:00:00 2001 From: Evgeny Arshinov Date: Thu, 18 Nov 2021 19:19:02 +0300 Subject: [PATCH 3/4] fix typo in test --- premailer/tests/test_merge_style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/premailer/tests/test_merge_style.py b/premailer/tests/test_merge_style.py index 72e7b9e..46e6ac1 100644 --- a/premailer/tests/test_merge_style.py +++ b/premailer/tests/test_merge_style.py @@ -24,5 +24,5 @@ def test_constituent_styles(self): csstext = merge_styles(inline_style, new_styles, classes) self.assertEqual( # ideally premailer could eliminate margin-bottom altogether - [("margin-bottom", "5px"), ("margin", "0")], csstext_to_pairs(csstext) + [("margin-bottom", "10px"), ("margin", "0")], csstext_to_pairs(csstext) ) From 54c6923fd34a2fe172b43bab78ec183a58e3cd85 Mon Sep 17 00:00:00 2001 From: Evgeny Arshinov Date: Thu, 18 Nov 2021 19:19:09 +0300 Subject: [PATCH 4/4] fix lint --- premailer/tests/test_merge_style.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/premailer/tests/test_merge_style.py b/premailer/tests/test_merge_style.py index 46e6ac1..14fd4ff 100644 --- a/premailer/tests/test_merge_style.py +++ b/premailer/tests/test_merge_style.py @@ -24,5 +24,6 @@ def test_constituent_styles(self): csstext = merge_styles(inline_style, new_styles, classes) self.assertEqual( # ideally premailer could eliminate margin-bottom altogether - [("margin-bottom", "10px"), ("margin", "0")], csstext_to_pairs(csstext) + [("margin-bottom", "10px"), ("margin", "0")], + csstext_to_pairs(csstext), )