From e439d38ca63c624cbd6506bff80141aacd9d311d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 7 Sep 2019 08:22:46 +0200 Subject: [PATCH] Improved plain text formatting --- .../main/java/eu/faircode/email/HtmlHelper.java | 14 +++++++++++++- 1 file changed, 13 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 554d5a968d..695046cffa 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -637,17 +637,27 @@ public class HtmlHelper { NodeTraversor.traverse(new NodeVisitor() { private int qlevel = 0; private int tlevel = 0; + private int plevel = 0; private boolean nl = true; public void head(Node node, int depth) { if (node instanceof TextNode) - append(((TextNode) node).text()); + if (plevel > 0) { + String[] lines = ((TextNode) node).getWholeText().split("\\r?\\n"); + for (String line : lines) { + append(line); + newline(); + } + } else + append(((TextNode) node).text()); else { String name = node.nodeName(); if ("li".equals(name)) append("*"); else if ("blockquote".equals(name)) qlevel++; + else if ("pre".equals(name)) + plevel++; if (heads.contains(name)) newline(); @@ -666,6 +676,8 @@ public class HtmlHelper { newline(); } else if ("blockquote".equals(name)) qlevel--; + else if ("pre".equals(name)) + plevel--; if (tails.contains(name)) newline();