mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-31 20:25:38 +00:00
Guess schemes / relative links for images
This commit is contained in:
parent
5d034b7b90
commit
91a78116e8
1 changed files with 15 additions and 17 deletions
|
@ -1301,26 +1301,23 @@ public class HtmlHelper {
|
|||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||
Elements b = document.select("base");
|
||||
String base = (b.size() > 0 ? b.get(0).attr("href") : null);
|
||||
for (Element a : document.select("a")) {
|
||||
String href = a.attr("href");
|
||||
|
||||
if (href.contains(" ")) {
|
||||
href = href.replace(" ", "%20");
|
||||
a.attr("href", href);
|
||||
}
|
||||
for (Element e : document.select("a,img")) {
|
||||
String attr = ("a".equals(e.tagName()) ? "href" : "src");
|
||||
String link = e.attr(attr);
|
||||
|
||||
if (!TextUtils.isEmpty(base))
|
||||
try {
|
||||
// https://developer.android.com/reference/java/net/URI
|
||||
href = URI.create(base).resolve(href).toString();
|
||||
a.attr("href", href);
|
||||
link = URI.create(base).resolve(link.replace(" ", "%20")).toString();
|
||||
e.attr(attr, link);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
if (href.trim().startsWith("#")) {
|
||||
a.tagName("span");
|
||||
a.removeAttr("href");
|
||||
if ("a".equals(e.tagName()) &&
|
||||
link.trim().startsWith("#")) {
|
||||
e.tagName("span");
|
||||
e.removeAttr(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1422,13 +1419,14 @@ public class HtmlHelper {
|
|||
}
|
||||
|
||||
static void guessSchemes(Document document) {
|
||||
for (Element a : document.select("a"))
|
||||
for (Element e : document.select("a,img"))
|
||||
try {
|
||||
String href = a.attr("href");
|
||||
if (TextUtils.isEmpty(href))
|
||||
String attr = ("a".equals(e.tagName()) ? "href" : "src");
|
||||
String url = e.attr(attr);
|
||||
if (TextUtils.isEmpty(url))
|
||||
continue;
|
||||
Uri uri = UriHelper.guessScheme(Uri.parse(href));
|
||||
a.attr("href", uri.toString());
|
||||
Uri uri = UriHelper.guessScheme(Uri.parse(url));
|
||||
e.attr(attr, uri.toString());
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue