Fixed clearing annotations

pull/190/head
M66B 4 years ago
parent bbd66a22bb
commit 19e232061f

@ -1093,14 +1093,16 @@ public class FragmentCompose extends FragmentBase {
Element p = document.createElement("p");
p.html(TextUtils.join("<br>", line));
document.body().appendChild(p);
return document.html();
} else {
Document d = HtmlHelper.sanitizeCompose(context, ref.outerHtml(), true);
Element b = d.body();
b.tagName("div");
document.body().appendChild(b);
}
return document.html();
Spanned spanned = HtmlHelper.fromDocument(context, document, null, null);
return HtmlHelper.toHtml(spanned, context);
}
}
@Override
@ -3571,8 +3573,11 @@ public class FragmentCompose extends FragmentBase {
String b = args.getString("body", "");
if (!TextUtils.isEmpty(b)) {
Document d = HtmlHelper.sanitizeCompose(context, b, false);
Element e = d.body();
e.tagName("div");
Spanned spanned = HtmlHelper.fromDocument(context, d, null, null);
String shtml = HtmlHelper.toHtml(spanned, context);
Element e = document
.createElement("div")
.html(shtml);
document.body().appendChild(e);
}
@ -3708,8 +3713,11 @@ public class FragmentCompose extends FragmentBase {
if (ref.content) {
String html = Helper.readText(ref.getFile(context));
Document d = HtmlHelper.sanitizeCompose(context, html, true);
Element e = d.body();
e.tagName("div");
Spanned spanned = HtmlHelper.fromDocument(context, d, null, null);
String shtml = HtmlHelper.toHtml(spanned, context);
Element e = document
.createElement("div")
.html(shtml);
document.body().appendChild(e);
}
} else if ("list".equals(action)) {
@ -4046,6 +4054,7 @@ public class FragmentCompose extends FragmentBase {
refFile.delete();
}
// Could be external draft
Document document = HtmlHelper.sanitizeCompose(context, doc.html(), true);
for (Element e : ref)
@ -4488,6 +4497,7 @@ public class FragmentCompose extends FragmentBase {
b = Document.createShell("");
else
b = HtmlHelper.sanitizeCompose(context, body, true);
HtmlHelper.clearAnnotations(b);
if (draft.revision == null) {
draft.revision = 1;
@ -4531,6 +4541,7 @@ public class FragmentCompose extends FragmentBase {
addSignature(context, d, draft, identity);
}
HtmlHelper.clearAnnotations(d);
body = d.html();
// Create new revision

@ -328,20 +328,7 @@ public class HtmlHelper {
static Document sanitizeCompose(Context context, String html, boolean show_images) {
try {
Document d = sanitize(context, JsoupEx.parse(html), false, show_images);
d.select("*")
.removeAttr("x-block")
.removeAttr("x-inline")
.removeAttr("x-paragraph")
.removeAttr("x-font-size")
.removeAttr("x-font-size-rel")
.removeAttr("x-line-before")
.removeAttr("x-line-after")
.removeAttr("x-align")
.removeAttr("x-column")
.removeAttr("x-dashed")
.removeAttr("x-tracking");
return d;
return sanitize(context, JsoupEx.parse(html), false, show_images);
} catch (Throwable ex) {
// OutOfMemoryError
Log.e(ex);
@ -2520,6 +2507,21 @@ public class HtmlHelper {
return ssb;
}
static void clearAnnotations(Document d) {
d.select("*")
.removeAttr("x-block")
.removeAttr("x-inline")
.removeAttr("x-paragraph")
.removeAttr("x-font-size")
.removeAttr("x-font-size-rel")
.removeAttr("x-line-before")
.removeAttr("x-line-after")
.removeAttr("x-align")
.removeAttr("x-column")
.removeAttr("x-dashed")
.removeAttr("x-tracking");
}
static Spanned fromHtml(@NonNull String html, Context context) {
return fromHtml(html, null, null, context);
}

Loading…
Cancel
Save