function escape(text) {
var e = {
"<": "<",
">": ">",
"'": "'"
};
return text.replace(/[<>']/g, function (c) {
return e[c];
});
}
Handlebars.registerHelper(
"parse", function(text) {
text = uri(text);
text = wraplong(text);
return text;
}
);
function uri(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 = "" + url + "";
}
text = text.replace(
"$(" + i + ")", replace
);
}
return text;
}
function wraplong(text) {
var wrap = false;
var split = text.split(" ");
for (var i in split) {
if (split[i].length > 40) {
wrap = true;
}
}
if (wrap) {
return "" + text + "";
} else {
return text;
}
}