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
boolean linked = false;
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();
if (TextUtils.isEmpty(text))
text = parent.attr("alt").trim();
@ -235,18 +236,20 @@ public class HtmlHelper {
img.remove();
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;
break;
}
if (!linked)
img.replaceWith(div);
if (!linked) {
img.tagName("div");
img.html(div.html());
}
}
// Autolink