Guess scheme for outbound autolink

pull/207/head
M66B 4 years ago
parent 17de80ec5d
commit 05a73fcfe2

@ -1415,6 +1415,10 @@ public class HtmlHelper {
} }
static void autoLink(Document document) { static void autoLink(Document document) {
autoLink(document, false);
}
static void autoLink(Document document, boolean outbound) {
// https://en.wikipedia.org/wiki/List_of_URI_schemes // https://en.wikipedia.org/wiki/List_of_URI_schemes
// xmpp:[<user>]@<host>[:<port>]/[<resource>][?<query>] // xmpp:[<user>]@<host>[:<port>]/[<resource>][?<query>]
// geo:<lat>,<lon>[,<alt>][;u=<uncertainty>] // geo:<lat>,<lon>[,<alt>][;u=<uncertainty>]
@ -1500,8 +1504,18 @@ public class HtmlHelper {
Element a = document.createElement("a"); Element a = document.createElement("a");
if (BuildConfig.DEBUG && GPA_PATTERN.matcher(group).matches()) if (BuildConfig.DEBUG && GPA_PATTERN.matcher(group).matches())
a.attr("href", BuildConfig.GPA_URI + group); a.attr("href", BuildConfig.GPA_URI + group);
else else {
a.attr("href", (email ? "mailto:" : "") + group); 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); a.text(group);
span.appendChild(a); span.appendChild(a);

@ -926,7 +926,7 @@ public class MessageHelper {
if (identity != null && send) { if (identity != null && send) {
if (auto_link) { if (auto_link) {
HtmlHelper.guessSchemes(document); HtmlHelper.guessSchemes(document);
HtmlHelper.autoLink(document); HtmlHelper.autoLink(document, true);
} }
if (!TextUtils.isEmpty(compose_font)) { if (!TextUtils.isEmpty(compose_font)) {

Loading…
Cancel
Save