Simplified newline handling

This commit is contained in:
M66B 2020-08-11 13:21:28 +02:00
parent 092b361fd9
commit 944cd535e3
5 changed files with 49 additions and 25 deletions

View File

@ -233,7 +233,7 @@ public class ActivitySignature extends ActivityBase {
return etText.getText().toString();
else {
String html = HtmlHelper.toHtml(etText.getText(), this);
Document d = HtmlHelper.fixEdit(JsoupEx.parse(html));
Document d = JsoupEx.parse(html);
return d.body().html();
}
}

View File

@ -272,7 +272,7 @@ public class FragmentAnswer extends FragmentBase {
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
Document document = HtmlHelper.fixEdit(JsoupEx.parse(html));
Document document = JsoupEx.parse(html);
DB db = DB.getInstance(context);
if (id < 0) {

View File

@ -276,7 +276,7 @@ public class HtmlEx {
private /* static */ void withinBlockquoteConsecutive(StringBuilder out, Spanned text, int start,
int end) {
out.append("<p").append(getTextDirection(text, start, end)).append(">");
out.append("<span").append(getTextDirection(text, start, end)).append(">");
int next;
for (int i = start; i < end; i = next) {
@ -294,21 +294,21 @@ public class HtmlEx {
withinParagraph(out, text, i, next - nl);
if (nl == 1) {
if (nl == 0) {
out.append("<br>\n");
} else {
for (int j = 2; j < nl; j++) {
for (int j = 0; j < nl; j++) {
out.append("<br>");
}
if (next != end) {
/* Paragraph should be closed and reopened */
out.append("</p>\n");
out.append("<p").append(getTextDirection(text, start, end)).append(">");
out.append("</span>\n");
out.append("<span").append(getTextDirection(text, start, end)).append(">");
}
}
}
out.append("</p>\n");
out.append("</span>\n");
}
private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) {

View File

@ -289,7 +289,7 @@ public class HtmlHelper {
static Document sanitizeCompose(Context context, String html, boolean show_images) {
try {
Document parsed = fixEdit(JsoupEx.parse(html));
Document parsed = JsoupEx.parse(html);
return sanitize(context, parsed, false, show_images);
} catch (Throwable ex) {
// OutOfMemoryError
@ -302,22 +302,6 @@ public class HtmlHelper {
}
}
static Document fixEdit(Document document) {
// Prevent extra newline at end
Element body = document.body();
if (body != null && body.childrenSize() > 0) {
Element holder = body.child(body.childrenSize() - 1);
if ("p".equals(holder.tagName())) {
holder.tagName("span");
int c = holder.childNodeSize();
Node last = (c > 0 ? holder.childNode(c - 1) : null);
if (last == null || !"br".equals(last.nodeName()))
holder.appendChild(new Element("br"));
}
}
return document;
}
static Document sanitizeView(Context context, Document parsed, boolean show_images) {
try {
return sanitize(context, parsed, true, show_images);

40
patches/HtmlEx.patch Normal file
View File

@ -0,0 +1,40 @@
diff --git a/app/src/main/java/eu/faircode/email/HtmlEx.java b/app/src/main/java/eu/faircode/email/HtmlEx.java
index c8b8e1b8f..5cfceaccd 100644
--- a/app/src/main/java/eu/faircode/email/HtmlEx.java
+++ b/app/src/main/java/eu/faircode/email/HtmlEx.java
@@ -276,7 +276,7 @@ public class HtmlEx {
private /* static */ void withinBlockquoteConsecutive(StringBuilder out, Spanned text, int start,
int end) {
- out.append("<p").append(getTextDirection(text, start, end)).append(">");
+ out.append("<span").append(getTextDirection(text, start, end)).append(">");
int next;
for (int i = start; i < end; i = next) {
@@ -294,21 +294,21 @@ public class HtmlEx {
withinParagraph(out, text, i, next - nl);
- if (nl == 1) {
+ if (nl == 0) {
out.append("<br>\n");
} else {
- for (int j = 2; j < nl; j++) {
+ for (int j = 0; j < nl; j++) {
out.append("<br>");
}
if (next != end) {
/* Paragraph should be closed and reopened */
- out.append("</p>\n");
- out.append("<p").append(getTextDirection(text, start, end)).append(">");
+ out.append("</span>\n");
+ out.append("<span").append(getTextDirection(text, start, end)).append(">");
}
}
}
- out.append("</p>\n");
+ out.append("</span>\n");
}
private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) {