From 0da95d142268d0173ce0d73875b56e1c8f93d1da Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 26 Aug 2023 18:21:04 +0200 Subject: [PATCH] Revert "Merge styles for elements only" This reverts commit 389fa78fa9e0ebb2a50e56171c56e3fcbfff7227. --- .../java/eu/faircode/email/HtmlHelper.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index b773700d71..4f62913ce5 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1795,7 +1795,7 @@ public class HtmlHelper { if (tag == null ? eselector.getLocalName() == null : tag.equalsIgnoreCase(eselector.getLocalName())) - style = mergeStyles(style, srule.getStyle().getCssText()); + style = mergeStyles(style, srule.getStyle().getCssText(), false); break; case Selector.SAC_CONDITIONAL_SELECTOR: if (!TextUtils.isEmpty(clazz)) { @@ -1805,7 +1805,7 @@ public class HtmlHelper { String value = ccondition.getValue(); for (String cls : clazz.split("\\s+")) if (cls.equalsIgnoreCase(value)) { - style = mergeStyles(style, srule.getStyle().getCssText()); + style = mergeStyles(style, srule.getStyle().getCssText(), false); break; } @@ -1842,6 +1842,10 @@ public class HtmlHelper { } static String mergeStyles(String base, String style) { + return mergeStyles(base, style, true); + } + + private static String mergeStyles(String base, String style, boolean element) { Map result = new HashMap<>(); // Base style @@ -1873,18 +1877,19 @@ public class HtmlHelper { //https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance#controlling_inheritance boolean initial = false; // no value boolean inherit = false; // parent value - switch (value) { - case "inherit": - inherit = true; - break; - case "initial": - initial = true; - break; - case "unset": - case "revert": - inherit = !STYLE_NO_INHERIT.contains(key); - break; - } + if (element) + switch (value) { + case "inherit": + inherit = true; + break; + case "initial": + initial = true; + break; + case "unset": + case "revert": + inherit = !STYLE_NO_INHERIT.contains(key); + break; + } if (initial || inherit) Log.i("CSS " + value + "=" + key); @@ -1900,7 +1905,8 @@ public class HtmlHelper { } for (String key : baseParams.keySet()) - result.put(key, baseParams.get(key)); + if (!STYLE_NO_INHERIT.contains(key) || element) + result.put(key, baseParams.get(key)); return TextUtils.join(";", result.values()); }