# HG changeset patch # User Atul Varma # Date 1231203721 28800 # Node ID ccc558eb70db2d24c49e3b0d54ba59f31ef901f7 # Parent 0c1314b3ea798deb572507eca671c2922bb2a890 Comments are now chunked into blocks. diff -r 0c1314b3ea79 -r ccc558eb70db samplecode.js --- 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() { // } diff -r 0c1314b3ea79 -r ccc558eb70db thingy.js --- 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(