From 681e0c87ef513304a1f2ce5310f9c59b85f0c77a Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 26 Mar 2019 13:37:04 +0000 Subject: [PATCH] Remove extra trailing newlines from spans --- app/src/main/java/eu/faircode/email/HtmlHelper.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index ae0928dab1..6fcd9e0b30 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -566,7 +566,15 @@ public class HtmlHelper { } static Spanned fromHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) { - return HtmlCompat.fromHtml(html, FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM, imageGetter, tagHandler); + Spanned spanned = HtmlCompat.fromHtml(html, FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM, imageGetter, tagHandler); + + int i = spanned.length(); + while (i > 1 && spanned.charAt(i - 2) == '\n' && spanned.charAt(i - 1) == '\n') + i--; + if (i != spanned.length()) + spanned = (Spanned) spanned.subSequence(0, i); + + return spanned; } static String toHtml(Spanned spanned) {