Add support for rendering xmpp: and mailto: URIs

This commit is contained in:
JC Brand 2018-10-07 04:46:41 +02:00
parent 7a612460da
commit 6a5a502d58
2 changed files with 14 additions and 8 deletions

11
dist/converse.js vendored
View File

@ -81605,16 +81605,19 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}; };
u.addHyperlinks = function (text) { u.addHyperlinks = function (text) {
return URI.withinString(text, function (url) { return URI.withinString(text, url => {
var uri = new URI(url); const uri = new URI(url);
uri.normalize(); uri.normalize();
const pretty_url = uri._parts.urn ? url : uri.readable();
if (!url.startsWith('http://') && !url.startsWith('https://')) { if (!uri._parts.protocol && !url.startsWith('http://') && !url.startsWith('https://')) {
url = 'http://' + url; url = 'http://' + url;
} }
url = u.escapeHTML(u.escapeURL(url)); url = u.escapeHTML(u.escapeURL(url));
return `<a target="_blank" rel="noopener" href="${url}">${u.escapeHTML(uri.readable())}</a>`; return `<a target="_blank" rel="noopener" href="${url}">${u.escapeHTML(pretty_url)}</a>`;
}, {
'start': /\b(?:([a-z][a-z0-9.+-]*:\/\/)|xmpp:|mailto:|www\.)/gi
}); });
}; };

View File

@ -265,14 +265,17 @@
}; };
u.addHyperlinks = function (text) { u.addHyperlinks = function (text) {
return URI.withinString(text, function (url) { return URI.withinString(text, url => {
var uri = new URI(url); const uri = new URI(url);
uri.normalize(); uri.normalize();
if (!url.startsWith('http://') && !url.startsWith('https://')) { const pretty_url = uri._parts.urn ? url : uri.readable();
if (!uri._parts.protocol && !url.startsWith('http://') && !url.startsWith('https://')) {
url = 'http://' + url; url = 'http://' + url;
} }
url = u.escapeHTML(u.escapeURL(url)); url = u.escapeHTML(u.escapeURL(url));
return `<a target="_blank" rel="noopener" href="${url}">${u.escapeHTML(uri.readable())}</a>`; return `<a target="_blank" rel="noopener" href="${url}">${u.escapeHTML(pretty_url)}</a>`;
}, {
'start': /\b(?:([a-z][a-z0-9.+-]*:\/\/)|xmpp:|mailto:|www\.)/gi
}); });
}; };