Add Enyo layout repo
[blerg.git] / www / jssrc / blerg / Util.js
index 78081ed..18f3169 100644 (file)
@@ -3,9 +3,9 @@ blerg = window.blerg || {};
 blerg.Util = {};
 
 // Dirty, terrible shim for rewritten links below
-blerg.Util.qlink = function() {
+blerg.Util.qlink = function(ev) {
     try {
-        location.href = event.target.href;
+        location.href = ev.target.href;
     } catch(e) { }
     enyo.$.blerg.bubble('onNavigate');
     return false;
@@ -16,7 +16,7 @@ blerg.Util.formatLinkHooks = [
 ];
 
 blerg.Util.formatMarkdownLinks = function(l) {
-        m = l.match(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)(\s([^)]*))?\)/);
+        m = l.match(/(\s[()\[\]{}]?|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?|mailto:[^)"]*?)(\s([^)]*))?\)/);
         if (!m)
             return l;
         var whitespace = m[1];
@@ -72,7 +72,7 @@ blerg.Util.blergFormat = function(text) {
         l = l.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
         // Turn HTTP URLs into links
-        l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
+        l = l.replace(/(\s[()\[\]{}]?|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
 
         // Turn markdown links into links
         l = blerg.Util.formatMarkdownLinks(l);
@@ -82,8 +82,8 @@ blerg.Util.blergFormat = function(text) {
         l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1<i>$2</i>$3');
 
         // Turn refs and tags into links
-        l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return blerg.Util.qlink()">#$2</a>');
-        l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1<a href="#$2$3" class="ref" onclick="return blerg.Util.qlink()">@$2</a>');
+        l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return blerg.Util.qlink(event)">#$2</a>');
+        l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1<a href="#$2$3" class="ref" onclick="return blerg.Util.qlink(event)">@$2</a>');
 
         // Create lists when lines begin with *
         if (l[0] == '*') {