Guess scheme for outbound autolink

This commit is contained in:
M66B
2022-04-08 13:25:26 +02:00
parent 17de80ec5d
commit 05a73fcfe2
2 changed files with 17 additions and 3 deletions

View File

@@ -1415,6 +1415,10 @@ public class HtmlHelper {
}
static void autoLink(Document document) {
autoLink(document, false);
}
static void autoLink(Document document, boolean outbound) {
// https://en.wikipedia.org/wiki/List_of_URI_schemes
// xmpp:[<user>]@<host>[:<port>]/[<resource>][?<query>]
// geo:<lat>,<lon>[,<alt>][;u=<uncertainty>]
@@ -1500,8 +1504,18 @@ public class HtmlHelper {
Element a = document.createElement("a");
if (BuildConfig.DEBUG && GPA_PATTERN.matcher(group).matches())
a.attr("href", BuildConfig.GPA_URI + group);
else
a.attr("href", (email ? "mailto:" : "") + group);
else {
String url = (email ? "mailto:" : "") + group;
try {
Uri uri = Uri.parse(url);
if (outbound)
uri = UriHelper.guessScheme(uri);
a.attr("href", uri.toString());
} catch (Throwable ex) {
Log.e(ex);
a.attr("href", url);
}
}
a.text(group);
span.appendChild(a);