2014-07-07 23:13:12 +00:00
|
|
|
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);
|
2014-07-24 00:16:00 +00:00
|
|
|
return "$(" + (urls.length - 1) + ")";
|
2014-07-07 23:13:12 +00:00
|
|
|
});
|
|
|
|
text = escape(text);
|
|
|
|
for (var i in urls) {
|
|
|
|
var url = escape(urls[i]);
|
|
|
|
text = text.replace(
|
|
|
|
"$(" + i + ")",
|
|
|
|
"<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
);
|