Mercurial > doc-thingy
view thingy.js @ 5:dcae71b1c3b4
Changed sample code, removed a debug logging statement.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 05 Jan 2009 17:14:14 -0800 |
parents | ccc558eb70db |
children | dc88b0e46f2d |
line wrap: on
line source
var App = { FILENAME: "samplecode.js" }; App.trim = function trim(str) { return str.replace(/^\s+|\s+$/g,""); }; App.processCode = function processCode(code) { var lines = code.split('\n'); var blocks = []; var blockText = ""; var firstCommentLine; var lastCommentLine; function maybeAppendBlock() { if (blockText) blocks.push({text: blockText, lineno: firstCommentLine}); } jQuery.each( lines, function(lineNum) { var line = this; var isComment = (App.trim(line).indexOf("//") == 0); if (!isComment) return; var startIndex = line.indexOf("//"); var text = line.slice(startIndex + 3); 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: { WikiCreole: 'http://www.wikicreole.org/wiki/', Wikipedia: 'http://en.wikipedia.org/wiki/' }, linkFormat: '' }); jQuery.each( blocks, function(i) { creole.parse($("#content").get(0), this.text); }); }; $(window).ready( function() { jQuery.get(App.FILENAME, {}, App.processCode, "text"); });