X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FUtil.js;h=d47770eb8dcbc148cd2cb548b6535efea8681f5a;hb=80ad774f55998cc11e08694245dfd6cb1b49a86f;hp=1bfab4c10cebda7167981a6855b73445b67341d2;hpb=9818631aecddd827374a0c01b3ec287e7b018bb1;p=blerg.git diff --git a/www/jssrc/blerg/Util.js b/www/jssrc/blerg/Util.js index 1bfab4c..d47770e 100644 --- a/www/jssrc/blerg/Util.js +++ b/www/jssrc/blerg/Util.js @@ -2,112 +2,121 @@ blerg = window.blerg || {}; blerg.Util = {}; +// Dirty, terrible shim for rewritten links below +blerg.Util.qlink = function() { + try { + location.href = event.target.href; + } catch(e) { } + enyo.$.blerg.bubble('onNavigate'); + return false; +} + blerg.Util.blergFormat = function(text) { - var lines = text.split(/\r?\n/); - if (lines[lines.length - 1] == '') - lines.pop(); - - var out = ['
'];
- var endpush = null;
- var listMode = false;
- lines.forEach(function(l) {
- if (l == '') {
- if (out[out.length - 1] == '
') {
- out[out.length - 1] = '
'; - } - if (out[out.length - 1] == '') { - out.push(''); - out.push('
'); - listMode = false; - } - return; - } - - // Put quoted material into a special paragraph - if (l[0] == '>') { - var pi = out.lastIndexOf('
'); - if (pi != -1) { - out[pi] = '
';
- l = l.replace(/^>\s*/, '');
- }
- }
-
- // Sanitize HTML input
- 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');
-
- // 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');
-
- // Turn *foo* into italics and **foo** into bold
- l = l.replace(/([^\w\\]|^)\*\*(\w[^*]*)\*\*(\W|$)/g, '$1$2$3');
- l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1$2$3');
-
- // Turn refs and tags into links
- l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1#$2');
- l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1@$2');
-
- // Create lists when lines begin with *
- if (l[0] == '*') {
- if (!listMode) {
- var pi = out.lastIndexOf('
'); - out[pi] = '
') - out.pop(); - if (listMode) - out.push('
'];
+ var endpush = null;
+ var listMode = false;
+ lines.forEach(function(l) {
+ if (l == '') {
+ if (out[out.length - 1] == '
') {
+ out[out.length - 1] = '
'; + } + if (out[out.length - 1] == '') { + out.push(''); + out.push('
'); + listMode = false; + } + return; + } + + // Put quoted material into a special paragraph + if (l[0] == '>') { + var pi = out.lastIndexOf('
'); + if (pi != -1) { + out[pi] = '
';
+ l = l.replace(/^>\s*/, '');
+ }
+ }
+
+ // Sanitize HTML input
+ 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');
+
+ // 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');
+
+ // Turn *foo* into italics and **foo** into bold
+ l = l.replace(/([^\w\\]|^)\*\*(\w[^*]*)\*\*(\W|$)/g, '$1$2$3');
+ l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1$2$3');
+
+ // Turn refs and tags into links
+ l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1#$2');
+ l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1@$2');
+
+ // Create lists when lines begin with *
+ if (l[0] == '*') {
+ if (!listMode) {
+ var pi = out.lastIndexOf('
'); + out[pi] = '
') + out.pop(); + if (listMode) + out.push('