Refactoring

pull/157/head
M66B 6 years ago
parent 003d7c720e
commit 1072edaa78

@ -171,17 +171,21 @@ public class HtmlHelper {
// Abbreviations // Abbreviations
document.select("abbr").tagName("u"); document.select("abbr").tagName("u");
// Remove link tracking pixels // Subscript/Superscript
if (paranoid) for (Element subp : document.select("sub,sup")) {
for (Element img : document.select("img")) Element small = document.createElement("small");
if (isTrackingPixel(img)) { small.html(subp.html());
String src = img.attr("src"); subp.html(small.outerHtml());
img.removeAttr("src"); }
img.tagName("a");
img.attr("href", src); // Lists
img.appendText(context.getString(R.string.title_hint_tracking_image, for (Element li : document.select("li")) {
img.attr("width"), img.attr("height"))); li.tagName("span");
} li.prependText("* ");
li.appendElement("br"); // line break after list item
}
document.select("ol").tagName("div");
document.select("ul").tagName("div");
// Tables // Tables
for (Element col : document.select("th,td")) { for (Element col : document.select("th,td")) {
@ -209,27 +213,23 @@ public class HtmlHelper {
else else
table.tagName("div"); table.tagName("div");
// Lists // Remove link tracking pixels
for (Element li : document.select("li")) { if (paranoid)
li.tagName("span"); for (Element img : document.select("img"))
li.prependText("* "); if (isTrackingPixel(img)) {
li.appendElement("br"); // line break after list item String src = img.attr("src");
} img.removeAttr("src");
document.select("ol").tagName("div"); img.tagName("a");
document.select("ul").tagName("div"); img.attr("href", src);
img.appendText(context.getString(R.string.title_hint_tracking_image,
img.attr("width"), img.attr("height")));
}
// Autolink
final Pattern pattern = Pattern.compile( final Pattern pattern = Pattern.compile(
PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" + PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" +
PatternsCompat.AUTOLINK_WEB_URL.pattern()); PatternsCompat.AUTOLINK_WEB_URL.pattern());
// Subscript/Superscript
for (Element subp : document.select("sub,sup")) {
Element small = document.createElement("small");
small.html(subp.html());
subp.html(small.outerHtml());
}
// Autolink
NodeTraversor.traverse(new NodeVisitor() { NodeTraversor.traverse(new NodeVisitor() {
@Override @Override
public void head(Node node, int depth) { public void head(Node node, int depth) {

Loading…
Cancel
Save