Make images link to themselves

This commit is contained in:
M66B
2018-11-24 12:27:44 +01:00
parent 2a04594b0d
commit 37981b0ac3
2 changed files with 14 additions and 1 deletions

View File

@@ -36,8 +36,21 @@ public class HtmlHelper {
public static String sanitize(String html) {
Document document = Jsoup.parse(Jsoup.clean(html, Whitelist.relaxed().addProtocols("img", "src", "cid")));
for (Element tr : document.select("tr"))
tr.after("<br>");
for (Element img : document.select("img"))
if (img.hasParent() && !"a".equals(img.parent().tagName())) {
String src = img.attr("src");
if (src.startsWith("http://") || src.startsWith("https://")) {
Element a = document.createElement("a");
a.attr("href", src);
img.replaceWith(a);
a.appendChild(img);
}
}
NodeTraversor.traverse(new NodeVisitor() {
@Override
public void head(Node node, int depth) {