Add scripts to create myops-getqueryview:
[myops.git] / web / query / vendor / couchapp / lib / linkup.js
diff --git a/web/query/vendor/couchapp/lib/linkup.js b/web/query/vendor/couchapp/lib/linkup.js
new file mode 100644 (file)
index 0000000..4b1d5a6
--- /dev/null
@@ -0,0 +1,18 @@
+// this code makes http://example.com into a link, 
+// and also handles @name and #hashtag
+
+// todo add [[wiki_links]]
+
+var mustache = require("vendor/couchapp/lib/mustache");
+exports.encode = function(body, person_prefix, tag_prefix) {
+  body = mustache.escape(body);
+  person_prefix = person_prefix || "http://twitter.com/";
+  tag_prefix = tag_prefix || "http://delicious.com/tag/";
+  return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
+    return '<a target="_blank" href="'+a+'">'+a+'</a>';
+  }).replace(/\@([\w\-]+)/g,function(user,name) {
+    return '<a href="'+person_prefix+encodeURIComponent(name)+'">'+user+'</a>';
+  }).replace(/\#([\w\-\.]+)/g,function(word,tag) {
+    return '<a href="'+tag_prefix+encodeURIComponent(tag)+'">'+word+'</a>';
+  });
+};
\ No newline at end of file