changeset 4:ccc558eb70db

Comments are now chunked into blocks.
author Atul Varma <varmaa@toolness.com>
date Mon, 05 Jan 2009 17:02:01 -0800
parents 0c1314b3ea79
children dcae71b1c3b4
files samplecode.js thingy.js
diffstat 2 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/samplecode.js	Mon Jan 05 16:44:08 2009 -0800
+++ b/samplecode.js	Mon Jan 05 17:02:01 2009 -0800
@@ -10,6 +10,7 @@
 // * There.
 // * Dood.
 //
+
 // {{{
 //   function blarg() {
 //   }
--- a/thingy.js	Mon Jan 05 16:44:08 2009 -0800
+++ b/thingy.js	Mon Jan 05 17:02:01 2009 -0800
@@ -8,19 +8,37 @@
 
 App.processCode = function processCode(code) {
   var lines = code.split('\n');
-  var block = "";
+  var blocks = [];
+  var blockText = "";
+  var firstCommentLine;
+  var lastCommentLine;
+
+  function maybeAppendBlock() {
+    if (blockText)
+      blocks.push({text: blockText,
+                   lineno: firstCommentLine});
+  }
 
   jQuery.each(
     lines,
-    function(i) {
+    function(lineNum) {
       var line = this;
+      var isComment = (App.trim(line).indexOf("//") == 0);
+      if (!isComment)
+        return;
       var startIndex = line.indexOf("//");
-      if (startIndex == -1)
-        // This is a /* */-style comment, skip it.
-        return;
       var text = line.slice(startIndex + 3);
-      block += text + "\n";
+      if (lineNum == lastCommentLine + 1) {
+        blockText += text + "\n";
+        lastCommentLine += 1;
+      } else {
+        maybeAppendBlock();
+        firstCommentLine = lineNum;
+        lastCommentLine = lineNum;
+        blockText = text + "\n";
+      }
     });
+  maybeAppendBlock();
 
   var creole = new Parse.Simple.Creole(
     {interwiki: {
@@ -30,7 +48,12 @@
      linkFormat: ''
     });
 
-  creole.parse($("#content").get(0), block);
+  jQuery.each(
+    blocks,
+    function(i) {
+      creole.parse($("#content").get(0), this.text);
+      console.log(this.lineno);
+    });
 };
 
 $(window).ready(