mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 14:41:08 +00:00
Allow colors
This commit is contained in:
parent
5b243b5a0f
commit
ec7ea93642
1 changed files with 22 additions and 0 deletions
|
@ -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()))
|
||||||
|
|
Loading…
Reference in a new issue