Never miss an old file
[myops.git] / web / query / vendor / couchapp / lib / linkup.js
1 // this code makes http://example.com into a link, 
2 // and also handles @name and #hashtag
3
4 // todo add [[wiki_links]]
5
6 var mustache = require("vendor/couchapp/lib/mustache");
7 exports.encode = function(body, person_prefix, tag_prefix) {
8   body = mustache.escape(body);
9   person_prefix = person_prefix || "http://twitter.com/";
10   tag_prefix = tag_prefix || "http://delicious.com/tag/";
11   return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
12     return '<a target="_blank" href="'+a+'">'+a+'</a>';
13   }).replace(/\@([\w\-]+)/g,function(user,name) {
14     return '<a href="'+person_prefix+encodeURIComponent(name)+'">'+user+'</a>';
15   }).replace(/\#([\w\-\.]+)/g,function(word,tag) {
16     return '<a href="'+tag_prefix+encodeURIComponent(tag)+'">'+word+'</a>';
17   });
18 };