Fixed HTML image processing

pull/155/head
M66B 6 years ago
parent fbe5a11682
commit cd50a90b2b

@ -166,69 +166,53 @@ public class HtmlHelper {
String title = img.attr("title"); String title = img.attr("title");
boolean tracking = (paranoid && isTrackingPixel(img)); boolean tracking = (paranoid && isTrackingPixel(img));
// Create image container
Element div = document.createElement("div");
// Remove link tracking pixel // Remove link tracking pixel
if (tracking) if (tracking)
img.removeAttr("src"); img.removeAttr("src");
// Link image to source // Create image container
Element a = document.createElement("a"); Element span = document.createElement("span");
a.attr("href", src); span.appendElement("br");
a.appendChild(img.clone()); span.appendChild(img.clone());
div.appendChild(a); span.appendElement("br");
// Show image title // Show image title
if (!TextUtils.isEmpty(title)) { if (!TextUtils.isEmpty(title)) {
div.appendElement("br"); span.appendElement("br");
div.appendElement("em").text(title); span.appendElement("em").text(title);
} }
if (!TextUtils.isEmpty(alt)) { if (!TextUtils.isEmpty(alt)) {
div.appendElement("br"); span.appendElement("br");
div.appendElement("em").text(alt); span.appendElement("em").text(alt);
} }
// Show when tracking pixel
if (tracking) { if (tracking) {
div.appendElement("br"); // Tracking pixel link
div.appendElement("em").text( span.appendElement("br");
context.getString(R.string.title_hint_tracking_image, Element a = document.createElement("a");
img.attr("width"), img.attr("height"))); a.attr("href", src);
} a.appendText(context.getString(R.string.title_hint_tracking_image,
img.attr("width"), img.attr("height")));
// Split parent link and linked image span.appendChild(a);
boolean linked = false; } else if (paranoid) {
if (paranoid) // Image link
for (Element parent : img.parents()) for (Element parent : img.parents())
if ("a".equals(parent.tagName()) && if ("a".equals(parent.tagName()) &&
!TextUtils.isEmpty(parent.attr("href"))) { !TextUtils.isEmpty(parent.attr("href"))) {
String text = parent.attr("title").trim(); span.appendElement("br");
if (TextUtils.isEmpty(text)) Element a = document.createElement("a");
text = parent.attr("alt").trim(); a.attr("href", src);
if (TextUtils.isEmpty(text)) a.appendText(context.getString(R.string.title_hint_image_link));
text = context.getString(R.string.title_hint_image_link); span.appendChild(a);
img.remove();
parent.appendText(text);
String outer = parent.outerHtml();
parent.tagName("span");
for (Attribute attr : parent.attributes().asList())
parent.attributes().remove(attr.getKey());
parent.html(outer);
parent.prependChild(div);
linked = true;
break; break;
} }
if (!linked) {
img.tagName("div");
for (Attribute attr : img.attributes().asList())
img.attributes().remove(attr.getKey());
img.html(div.html());
} }
// Replace img by span containing img
img.tagName("span");
for (Attribute attr : img.attributes().asList())
img.attributes().remove(attr.getKey());
img.html(span.html());
} }
// Tables // Tables

Loading…
Cancel
Save