commit:733ed5e9b18378a05accc9d8fa86c69709734c30
author:Chip Black
committer:Chip Black
date:Tue Mar 1 00:19:15 2011 -0800
parents:a2ca84770dd9230c1c6d4e2f08b0d3638604d99a
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).
diff --git a/www/css/blerg.css b/www/css/blerg.css
line changes: +1/-0
index 6fe2054..3867c3b
--- 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
line changes: +1/-1
index 04042a3..06be484
--- a/www/index.html
+++ b/www/index.html
@@ -20,7 +20,7 @@
     <h1><a href="/">Blërg!</a></h1>
     <h2><span name="section">Welcome</span></h2>
     <div id="usercontrols" style="display:none">
-      <a href="#" name="user.reflink">[chatter]</a>
+      <a href="#" name="user.reflink" onclick="return qlink()">[chatter]</a>
       <a href="#" name="user.subscribelink" onclick="subscribe(); return false" style="display: none">[stalk]</a>
       <a href="#" name="user.unsubscribelink" onclick="unsubscribe(); return false" style="display: none">[stop stalking]</a>
     </div>

diff --git a/www/js/blerg.js b/www/js/blerg.js
line changes: +27/-20
index 9b1db74..7203f09
--- 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('<p>');
             if (pi != -1) {
@@ -314,6 +315,25 @@ function mangleRecord(record, template) {
                 l = l.replace(/^>\s*/, '');
             }
         }
+
+        // Sanitize HTML input
+        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>');
+
+        // Turn markdown links into links
+        l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1<a href="$3">$2</a>');
+
+        // Turn *foo* into italics and **foo** into bold
+        l = l.replace(/(\W|^)\*\*([^*]+)\*\*(\W|$)/g, '$1<b>$2</b>$3');
+        l = l.replace(/(\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 qlink()">#$2</a>');
+        l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)/g, '$1<a href="#$2" class="ref" onclick="return qlink()">@$2</a>');
+
+        // Create lists when lines begin with *
         if (l[0] == '*') {
             if (!listMode) {
                 var pi = out.lastIndexOf('<p>');
@@ -324,6 +344,8 @@ function mangleRecord(record, template) {
             out.push('<li>');
             endpush = '</li>';
         }
+
+        // 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, '&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>');
-
-        // Turn markdown links into links
-        l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1<a href="$3">$2</a>');
-
-        // Turn *foo* into italics and **foo** into bold
-        l = l.replace(/(\s)\*\*([^*]+)\*\*(\s)/g, '$1<b>$2</b>$3');
-        l = l.replace(/(\s)\*([^*]+)\*(\s)/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 qlink()">#$2</a>');
-        l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)/g, '$1<a href="#$2" class="ref" onclick="return qlink()">@$2</a>');
-
         out.push(l);
         if (endpush) {
             out.push(endpush);
@@ -361,6 +366,8 @@ function mangleRecord(record, template) {
     });
     while (out[out.length - 1] == '<br>' || out[out.length - 1] == '<p>')
         out.pop();
+    if (listMode)
+        out.push('</ul>');
 
     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();
         }