diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 95dc74af83..433242bfbe 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -2244,10 +2244,6 @@ public class HtmlHelper { (i == 0 || endsWithSpace(block.get(i - 1).text()))) text = text.substring(1); - // Conditionally remove trailing whitespace - if (i == block.size() - 1 && endsWithSpace(text)) - text = text.substring(0, text.length() - 1); - tnode.text(text); if (TextUtils.isEmpty(text)) @@ -2256,6 +2252,20 @@ public class HtmlHelper { i++; } + // Remove trailing whitespace + while (block.size() > 0) { + tnode = block.get(block.size() - 1); + text = tnode.getWholeText(); + if (endsWithSpace(text)) { + text = text.substring(0, text.length() - 1); + tnode.text(text); + } + if (TextUtils.isEmpty(text)) + block.remove(block.size() - 1); + else + break; + } + // Remove all blank blocks boolean blank = true; for (int i = 0; i < block.size(); i++) {