Added support for base element

pull/206/head
M66B 3 years ago
parent d68eedf78d
commit 12479b7603

@ -105,6 +105,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.net.URI;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.util.ArrayList; import java.util.ArrayList;
@ -1246,11 +1247,23 @@ public class HtmlHelper {
} }
static void removeRelativeLinks(Document document) { static void removeRelativeLinks(Document document) {
for (Element a : document.select("a")) Elements b = document.select("base");
if (a.attr("href").trim().startsWith("#")) { String base = (b.size() > 0 ? b.get(0).attr("href") : null);
for (Element a : document.select("a")) {
String href = a.attr("href");
if (href.trim().startsWith("#")) {
a.tagName("span"); a.tagName("span");
a.removeAttr("href"); a.removeAttr("href");
} } else if (!TextUtils.isEmpty(base))
try {
// https://developer.android.com/reference/java/net/URI
URI u = URI.create(base);
URI r = u.resolve(href);
a.attr("href", r.toString());
} catch (Throwable ex) {
Log.w(ex);
}
}
} }
static void autoLink(Document document) { static void autoLink(Document document) {

Loading…
Cancel
Save