From 2d951d3b7a2c78fcaef5411787d82b881ba27f59 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 16 Jun 2020 20:05:55 +0200 Subject: [PATCH] Suppress extra p new line when margin/padding is zero --- .../java/eu/faircode/email/HtmlHelper.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 8871508821..bc12b40662 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -659,10 +659,16 @@ public class HtmlHelper { else if (key.endsWith("bottom")) p[0] = null; - if (p[0] != null && p[0] > 0.5) - element.attr("x-line-before", "true"); - if (p[2] != null && p[2] > 0.5) - element.attr("x-line-after", "true"); + if (p[0] != null) + if (p[0] == 0) + element.attr("x-line-before", "false"); + else if (p[0] > 0.5) + element.attr("x-line-before", "true"); + if (p[2] != null) + if (p[2] == 0) + element.attr("x-line-after", "false"); + else if (p[2] > 0.5) + element.attr("x-line-after", "true"); } break; @@ -704,7 +710,8 @@ public class HtmlHelper { // Paragraphs for (Element p : document.select("p")) { - p.appendElement("br"); + if (!"false".equals(p.attr("x-line-after"))) + p.appendElement("br"); p.tagName("div"); } @@ -958,13 +965,13 @@ public class HtmlHelper { div.tagName("span"); for (Element e : document.select("*[x-line-before],*[x-line-after]")) { - if (!TextUtils.isEmpty(e.attr("x-line-before"))) { + if ("true".equals(e.attr("x-line-before"))) { Element prev = e.previousElementSibling(); if (prev == null || !"br".equals(prev.tagName())) e.prependElement("br"); } - if (!TextUtils.isEmpty(e.attr("x-line-after"))) { + if ("true".equals(e.attr("x-line-after"))) { Element next = e.nextElementSibling(); if (next == null || !"br".equals(next.tagName())) e.appendElement("br");