From 733ed5e9b18378a05accc9d8fa86c69709734c30 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Tue, 1 Mar 2011 00:19:15 -0800 Subject: [PATCH] Fix qlink(), rearrange mangleRecord(), fix some style mangleRecord() should now processes bold/italics before lists, so it should properly distinguish between a * beginning a line and a * beginning a list (but maybe not). --- www/css/blerg.css | 1 + www/index.html | 2 +- www/js/blerg.js | 47 +++++++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/www/css/blerg.css b/www/css/blerg.css index 6fe2054..3867c3b 100644 --- a/www/css/blerg.css +++ b/www/css/blerg.css @@ -169,4 +169,5 @@ h1, h2, h3 { .quote { border-left: 2px solid blue; padding-left: 6px; + margin-left: 2px; } diff --git a/www/index.html b/www/index.html index 04042a3..06be484 100644 --- a/www/index.html +++ b/www/index.html @@ -20,7 +20,7 @@

Blërg!

Welcome

diff --git a/www/js/blerg.js b/www/js/blerg.js index 9b1db74..7203f09 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -307,6 +307,7 @@ function mangleRecord(record, template) { return; } + // Put quoted material into a special paragraph if (l[0] == '>') { var pi = out.lastIndexOf('

'); if (pi != -1) { @@ -314,6 +315,25 @@ function mangleRecord(record, template) { 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 + 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|$)/g, '$1$2$3'); + l = l.replace(/(\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_-]+)/g, '$1@$2'); + + // Create lists when lines begin with * if (l[0] == '*') { if (!listMode) { var pi = out.lastIndexOf('

'); @@ -324,6 +344,8 @@ function mangleRecord(record, template) { out.push('

  • '); endpush = '
  • '; } + + // Create headers when lines begin with = if (l[0] == '=') { var m = l.match(/^(=+)/); var depth = m[1].length; @@ -334,23 +356,6 @@ function mangleRecord(record, template) { } } - // 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 - 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(/(\s)\*\*([^*]+)\*\*(\s)/g, '$1$2$3'); - l = l.replace(/(\s)\*([^*]+)\*(\s)/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_-]+)/g, '$1@$2'); - out.push(l); if (endpush) { out.push(endpush); @@ -361,6 +366,8 @@ function mangleRecord(record, template) { }); while (out[out.length - 1] == '
    ' || out[out.length - 1] == '

    ') out.pop(); + if (listMode) + out.push(''); record.data = out.join(''); record.date = (new Date(record.timestamp * 1000)).toString(); @@ -662,8 +669,8 @@ function loadLatest() { function qlink(loc) { if (loc) { location.hash = loc; - } else if (this.href) { - location.hash = this.href; + } else if (event && event.target) { + location.href = event.target.href; } else { // Bogus qlink return; @@ -737,7 +744,7 @@ function init() { setInterval(hashCheck, 250); document.body.observe('keyup', function(event) { - if (event.shiftKey && event.keyCode == '32') { + if (event.shiftKey && event.keyCode == 32) { postPopup(); event.stop(); } -- 2.25.1