mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 17:13:23 +02:00
Fixed extra newlines
This commit is contained in:
@@ -288,13 +288,7 @@ public class HtmlHelper {
|
||||
|
||||
static Document sanitizeCompose(Context context, String html, boolean show_images) {
|
||||
try {
|
||||
Document parsed = JsoupEx.parse(html);
|
||||
|
||||
// Prevent extra newline at end
|
||||
Element body = parsed.body();
|
||||
if (body != null && body.childrenSize() == 1 && "p".equals(body.child(0).tagName()))
|
||||
body.child(0).tagName("span").appendChild(new Element("br"));
|
||||
|
||||
Document parsed = fixEdit(JsoupEx.parse(html));
|
||||
return sanitize(context, parsed, false, show_images);
|
||||
} catch (Throwable ex) {
|
||||
// OutOfMemoryError
|
||||
@@ -307,6 +301,22 @@ public class HtmlHelper {
|
||||
}
|
||||
}
|
||||
|
||||
static Document fixEdit(Document document) {
|
||||
// Prevent extra newline at end
|
||||
Element body = document.body();
|
||||
if (body != null && body.childrenSize() == 1) {
|
||||
Element holder = body.child(0);
|
||||
if ("p".equals(holder.tagName())) {
|
||||
holder.tagName("span");
|
||||
int c = holder.childrenSize();
|
||||
Element last = (c > 0 ? holder.child(c - 1) : null);
|
||||
if (last == null || !"br".equals(last.tagName()))
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user