X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FUtil.js;h=51489c9e0a2a94928e9fafe06110a16676d5b02d;hb=e01bce7710b1b70b003a2cccc8483fcda3d72014;hp=d47770eb8dcbc148cd2cb548b6535efea8681f5a;hpb=80ad774f55998cc11e08694245dfd6cb1b49a86f;p=blerg.git
diff --git a/www/jssrc/blerg/Util.js b/www/jssrc/blerg/Util.js
index d47770e..51489c9 100644
--- a/www/jssrc/blerg/Util.js
+++ b/www/jssrc/blerg/Util.js
@@ -11,6 +11,33 @@ blerg.Util.qlink = function() {
return false;
}
+blerg.Util.formatLinkHooks = [
+ BlergMedia
+];
+
+blerg.Util.formatMarkdownLinks = function(l) {
+ m = l.match(/(\s[()\[\]{}]?|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)(\s([^)]*))?\)/);
+ if (!m)
+ return l;
+ var whitespace = m[1];
+ var data = {
+ label: m[2],
+ url: m[3],
+ extra: m[5]
+ };
+
+ for (var i = 0; i < blerg.Util.formatLinkHooks.length; i++) {
+ var newdata = blerg.Util.formatLinkHooks[i].process(data);
+ if (newdata)
+ data = newdata;
+ else
+ console.warn("Format Link Hook " + i + " returned null");
+ }
+ var s = whitespace + '' + data.label + '' +
+ (data.widget ? ' ' + data.widget : '');
+ return l.slice(0, m.index) + s + blerg.Util.formatMarkdownLinks(l.slice(m.index + m[0].length));
+}
+
blerg.Util.blergFormat = function(text) {
var lines = text.split(/\r?\n/);
if (lines[lines.length - 1] == '')
@@ -45,31 +72,10 @@ blerg.Util.blergFormat = function(text) {
l = l.replace(/&/g, '&').replace(//g, '>');
// Turn HTTP URLs into links
- l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2');
+ l = l.replace(/(\s[()\[\]{}]?|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2');
// Turn markdown links into links
- var re;
-
- /*
- // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.audioExtensions.
- re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.audioExtensions.join('|') + '))\\)', 'g');
- l = l.replace(re, '$1$2 ');
-
- // Ditto, but use the extended markdown link syntax to specify the format
- re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+audio:(' + BlergMedia.audioExtensions.join('|') + ')\\)', 'g');
- l = l.replace(re, '$1$2 ');
-
- // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.videoExtensions.
- re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.videoExtensions.join('|') + '))\\)', 'g');
- l = l.replace(re, '$1$2 ');
-
- // Ditto, but use the extended markdown link syntax to specify the format
- re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+video:(' + BlergMedia.videoExtensions.join('|') + ')\\)', 'g');
- l = l.replace(re, '$1$2 ');
- */
-
- // Regular markdown links
- l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1$2');
+ l = blerg.Util.formatMarkdownLinks(l);
// Turn *foo* into italics and **foo** into bold
l = l.replace(/([^\w\\]|^)\*\*(\w[^*]*)\*\*(\W|$)/g, '$1$2$3');