mirror of
https://github.com/thelounge/thelounge
synced 2024-11-27 14:30:57 +00:00
32 lines
663 B
JavaScript
32 lines
663 B
JavaScript
function escape(text) {
|
|
var e = {
|
|
"<": "<",
|
|
">": ">",
|
|
"'": "'"
|
|
};
|
|
return text.replace(/[<>']/g, function (c) {
|
|
return e[c];
|
|
});
|
|
}
|
|
|
|
Handlebars.registerHelper(
|
|
"uri", function(text) {
|
|
var urls = [];
|
|
text = URI.withinString(text, function(url) {
|
|
urls.push(url);
|
|
return "$(" + (urls.length - 1) + ")";
|
|
});
|
|
text = escape(text);
|
|
for (var i in urls) {
|
|
var url = escape(urls[i]);
|
|
var replace = url;
|
|
if (url.indexOf("javascript:") !== 0) {
|
|
replace = "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
|
|
}
|
|
text = text.replace(
|
|
"$(" + i + ")", replace
|
|
);
|
|
}
|
|
return text;
|
|
}
|
|
);
|