|
|
@ -133,6 +133,7 @@ public class HtmlHelper {
|
|
|
|
|
|
|
|
|
|
|
|
Whitelist whitelist = Whitelist.relaxed()
|
|
|
|
Whitelist whitelist = Whitelist.relaxed()
|
|
|
|
.addTags("hr", "abbr", "big")
|
|
|
|
.addTags("hr", "abbr", "big")
|
|
|
|
|
|
|
|
.addAttributes("span", "style")
|
|
|
|
.removeTags("col", "colgroup", "thead", "tbody")
|
|
|
|
.removeTags("col", "colgroup", "thead", "tbody")
|
|
|
|
.removeAttributes("table", "width")
|
|
|
|
.removeAttributes("table", "width")
|
|
|
|
.removeAttributes("td", "colspan", "rowspan", "width")
|
|
|
|
.removeAttributes("td", "colspan", "rowspan", "width")
|
|
|
@ -141,6 +142,27 @@ public class HtmlHelper {
|
|
|
|
.addProtocols("img", "src", "data");
|
|
|
|
.addProtocols("img", "src", "data");
|
|
|
|
final Document document = new Cleaner(whitelist).clean(parsed);
|
|
|
|
final Document document = new Cleaner(whitelist).clean(parsed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sanitize span styles
|
|
|
|
|
|
|
|
for (Element span : document.select("span")) {
|
|
|
|
|
|
|
|
String style = span.attr("style");
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(style)) {
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] params = style.split(";");
|
|
|
|
|
|
|
|
for (String param : params) {
|
|
|
|
|
|
|
|
String[] kv = param.split(":");
|
|
|
|
|
|
|
|
if (kv.length == 2)
|
|
|
|
|
|
|
|
switch (kv[0].trim().toLowerCase()) {
|
|
|
|
|
|
|
|
case "color":
|
|
|
|
|
|
|
|
sb.append(param).append(";");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
span.attr("style", sb.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove new lines without surrounding content
|
|
|
|
// Remove new lines without surrounding content
|
|
|
|
for (Element br : document.select("br"))
|
|
|
|
for (Element br : document.select("br"))
|
|
|
|
if (br.parent() != null && !hasVisibleContent(br.parent().childNodes()))
|
|
|
|
if (br.parent() != null && !hasVisibleContent(br.parent().childNodes()))
|
|
|
|