Prevent crash

This commit is contained in:
M66B 2019-03-15 08:01:52 +00:00
parent 8a377e451f
commit 440cac41e8
1 changed files with 11 additions and 8 deletions

View File

@ -226,7 +226,8 @@ public class HtmlHelper {
// Split parent link and linked image // Split parent link and linked image
boolean linked = false; boolean linked = false;
for (Element parent : img.parents()) for (Element parent : img.parents())
if ("a".equals(parent.tagName()) && !TextUtils.isEmpty(parent.attr("href"))) { if ("a".equals(parent.tagName()) &&
!TextUtils.isEmpty(parent.attr("href"))) {
String text = parent.attr("title").trim(); String text = parent.attr("title").trim();
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
text = parent.attr("alt").trim(); text = parent.attr("alt").trim();
@ -235,18 +236,20 @@ public class HtmlHelper {
img.remove(); img.remove();
parent.appendText(text); parent.appendText(text);
String outer = parent.outerHtml();
parent.tagName("span");
parent.html(outer);
parent.appendChild(div);
Element span = document.createElement("span");
span.appendChild(parent.clone());
span.appendChild(div);
parent.replaceWith(span);
linked = true; linked = true;
break; break;
} }
if (!linked) if (!linked) {
img.replaceWith(div); img.tagName("div");
img.html(div.html());
}
} }
// Autolink // Autolink