Added fail safes

pull/217/head
M66B 10 months ago
parent 5046dcf3f4
commit 7bb58be0c2

@ -1739,61 +1739,67 @@ public class HtmlHelper {
String ns = null; String ns = null;
for (Element h : parsed.select("html")) for (Element h : parsed.select("html"))
for (Attribute a : h.attributes()) { for (Attribute a : h.attributes())
String key = a.getKey(); try {
String value = a.getValue().toLowerCase(Locale.ROOT); String key = a.getKey();
if ("xmlns".equals(key) && value.contains(W3NS)) { String value = a.getValue().toLowerCase(Locale.ROOT);
ns = key; if ("xmlns".equals(key) && value.contains(W3NS)) {
break; ns = key;
} else if (key.startsWith("xmlns:") && value.contains(W3NS)) { break;
ns = key.split(":")[1]; } else if (key.startsWith("xmlns:") && value.contains(W3NS)) {
break; ns = key.split(":")[1];
break;
}
} catch (Throwable ex) {
Log.e(ex);
} }
}
for (Element e : parsed.select("*")) { for (Element e : parsed.select("*"))
String tag = e.tagName(); try {
if (tag.contains(":")) { String tag = e.tagName();
boolean show = (ns == null || tag.startsWith(ns) || if (tag.contains(":")) {
tag.startsWith("html:") || tag.startsWith("body:") || tag.startsWith("w:")); boolean show = (ns == null || tag.startsWith(ns) ||
if (display_hidden || show) { tag.startsWith("html:") || tag.startsWith("body:") || tag.startsWith("w:"));
String[] nstag = tag.split(":"); if (display_hidden || show) {
String t = nstag[nstag.length > 1 ? 1 : 0]; String[] nstag = tag.split(":");
if (!TextUtils.isEmpty(t)) { String t = nstag[nstag.length > 1 ? 1 : 0];
e.tagName(t); if (!TextUtils.isEmpty(t)) {
Log.i("Updated tag=" + tag + " to=" + t); e.tagName(t);
} Log.i("Updated tag=" + tag + " to=" + t);
}
if (!show) { if (!show) {
String style = e.attr("style"); String style = e.attr("style");
e.attr("style", mergeStyles(style, "text-decoration:line-through;")); e.attr("style", mergeStyles(style, "text-decoration:line-through;"));
} }
} else if (TextUtils.isEmpty(e.text()) && !"\u00a0".equals(e.wholeText())) { } else if (TextUtils.isEmpty(e.text()) && !"\u00a0".equals(e.wholeText())) {
// <meta name=Generator content="Microsoft Word 15 (filtered medium)"> // <meta name=Generator content="Microsoft Word 15 (filtered medium)">
// <p class=MsoNormal> // <p class=MsoNormal>
// <span style='font-family:"Calibri",sans-serif'> // <span style='font-family:"Calibri",sans-serif'>
// <o:p>&nbsp;</o:p> // <o:p>&nbsp;</o:p>
// </span> // </span>
// </p> // </p>
e.remove();
Log.i("Removed tag=" + tag + " ns=" + ns +
" content=" + Helper.getPrintableString(e.wholeText(), true));
} else {
// Leave tag with unknown namespace to ensure all text is being displayed
}
} else if (!"html".equals(tag) && !"body".equals(tag) && !"w".equals(tag)) {
String xmlns = e.attr("xmlns").toLowerCase(Locale.ROOT);
if (!TextUtils.isEmpty(xmlns) && !xmlns.contains(W3NS)) {
if (display_hidden) {
String style = e.attr("style");
e.attr("style", mergeStyles(style, "text-decoration:line-through;"));
} else {
e.remove(); e.remove();
Log.i("Removed tag=" + tag + " ns=" + ns + " xmlns=" + xmlns + " content=" + e.text()); Log.i("Removed tag=" + tag + " ns=" + ns +
" content=" + Helper.getPrintableString(e.wholeText(), true));
} else {
// Leave tag with unknown namespace to ensure all text is being displayed
}
} else if (!"html".equals(tag) && !"body".equals(tag) && !"w".equals(tag)) {
String xmlns = e.attr("xmlns").toLowerCase(Locale.ROOT);
if (!TextUtils.isEmpty(xmlns) && !xmlns.contains(W3NS)) {
if (display_hidden) {
String style = e.attr("style");
e.attr("style", mergeStyles(style, "text-decoration:line-through;"));
} else {
e.remove();
Log.i("Removed tag=" + tag + " ns=" + ns + " xmlns=" + xmlns + " content=" + e.text());
}
} }
} }
} catch (Throwable ex) {
Log.e(ex);
} }
}
} }
static List<CSSStyleSheet> parseStyles(Elements styles) { static List<CSSStyleSheet> parseStyles(Elements styles) {

Loading…
Cancel
Save