Never more

This commit is contained in:
M66B
2020-02-10 18:03:25 +01:00
parent 81e97da66b
commit cf64335cb4
3 changed files with 26 additions and 6 deletions

View File

@@ -77,6 +77,7 @@ public class HtmlHelper {
private static final float MIN_LUMINANCE = 0.5f;
private static final int TAB_SIZE = 2;
private static final int MAX_AUTO_LINK = 250;
private static final int MAX_TEXT_SIZE = 50 * 1024; // characters
private static final int TRACKING_PIXEL_SURFACE = 25; // pixels
private static final List<String> heads = Collections.unmodifiableList(Arrays.asList(
@@ -714,11 +715,28 @@ public class HtmlHelper {
if (!TextUtils.isEmpty(span.attr("color")))
span.tagName("font");
int length = 0;
for (Element elm : document.select("*")) {
for (Node child : elm.childNodes())
if (child instanceof TextNode)
length += ((TextNode) child).text().length();
if (length > MAX_TEXT_SIZE)
elm.remove();
}
if (document.body() == null) {
Log.e("Sanitize without body");
document.normalise();
}
if (length > MAX_TEXT_SIZE)
document.body()
.appendElement("p")
.appendElement("big")
.appendElement("a")
.attr("href", "more:")
.text(context.getString(R.string.title_show_more));
return document;
}