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 = [] diff --git a/premailer/tests/test_merge_style.py b/premailer/tests/test_merge_style.py index 4b13e7e..14fd4ff 100644 --- a/premailer/tests/test_merge_style.py +++ b/premailer/tests/test_merge_style.py @@ -15,3 +15,15 @@ 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", "10px"), ("margin", "0")], + csstext_to_pairs(csstext), + )