mirror of https://github.com/M66B/FairEmail.git
Convert to lists on sending message
This commit is contained in:
parent
5f249f59b9
commit
b66e940727
|
@ -1192,8 +1192,8 @@ public class HtmlHelper {
|
||||||
append(((TextNode) node).text());
|
append(((TextNode) node).text());
|
||||||
else {
|
else {
|
||||||
String name = node.nodeName();
|
String name = node.nodeName();
|
||||||
if ("li".equals(name))
|
if ("li".equals(name) && node.parent() != null)
|
||||||
append("*");
|
append("ol".equals(node.parent().nodeName()) ? "-" : "*");
|
||||||
else if ("blockquote".equals(name))
|
else if ("blockquote".equals(name))
|
||||||
qlevel++;
|
qlevel++;
|
||||||
else if ("pre".equals(name))
|
else if ("pre".equals(name))
|
||||||
|
@ -1259,6 +1259,46 @@ public class HtmlHelper {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void convertLists(Document document) {
|
||||||
|
for (Element p : document.select("p")) {
|
||||||
|
Element list = null;
|
||||||
|
for (int i = 0; i < p.childNodeSize(); i++) {
|
||||||
|
boolean item = false;
|
||||||
|
Node node = p.childNode(i);
|
||||||
|
if (node instanceof TextNode) {
|
||||||
|
String text = ((TextNode) node).text().trim();
|
||||||
|
Node next = node.nextSibling();
|
||||||
|
if ((text.startsWith("* ") || text.startsWith("- ")) &&
|
||||||
|
(next == null || "br".equals(next.nodeName()))) {
|
||||||
|
item = true;
|
||||||
|
String type = (text.startsWith("* ") ? "ul" : "ol");
|
||||||
|
|
||||||
|
Element li = document.createElement("li");
|
||||||
|
li.text(text.substring(2));
|
||||||
|
|
||||||
|
if (list == null || !list.tagName().equals(type)) {
|
||||||
|
list = document.createElement(type);
|
||||||
|
list.appendChild(li);
|
||||||
|
node.replaceWith(list);
|
||||||
|
} else {
|
||||||
|
list.appendChild(li);
|
||||||
|
node.remove();
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next != null)
|
||||||
|
next.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!item)
|
||||||
|
list = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.tagName("div");
|
||||||
|
p.appendElement("br");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Spanned highlightHeaders(Context context, String headers) {
|
static Spanned highlightHeaders(Context context, String headers) {
|
||||||
int colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
|
int colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
|
||||||
SpannableStringBuilder ssb = new SpannableStringBuilder(headers);
|
SpannableStringBuilder ssb = new SpannableStringBuilder(headers);
|
||||||
|
|
|
@ -36,6 +36,7 @@ import com.sun.mail.util.QDecoderStream;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
@ -513,7 +514,20 @@ public class MessageHelper {
|
||||||
|
|
||||||
// When sending message
|
// When sending message
|
||||||
if (identity != null) {
|
if (identity != null) {
|
||||||
document.select("div[fairemail=signature],div[fairemail=reference]").removeAttr("fairemail");
|
Elements sig = document.select("div[fairemail=signature]");
|
||||||
|
Elements ref = document.select("div[fairemail=reference]");
|
||||||
|
sig.remove();
|
||||||
|
ref.remove();
|
||||||
|
|
||||||
|
HtmlHelper.convertLists(document);
|
||||||
|
|
||||||
|
sig.removeAttr("fairemail");
|
||||||
|
ref.removeAttr("fairemail");
|
||||||
|
|
||||||
|
for (Element e : sig)
|
||||||
|
document.body().appendChild(e);
|
||||||
|
for (Element e : ref)
|
||||||
|
document.body().appendChild(e);
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue