var fs = require('fs')
var sys = require('sys')
var http = require('http');
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }

var output = ""

fs.readFile('mondriaan.js','utf-8', function (err,data){
  data = data.
    replace(/\n/g,'').
    replace(/ /g,'').
    replace(/</g, '&lt;').
    replace(/'/g, '&#039;').
    replace(/"/g, '&quot;')

  rowlength = 1;
  rowloc = 1;

  for (i=0;i<data.length;i++) {
      output += data[i];

      if (rowloc == rowlength) {
          output += '</br>\n';
          rowloc = 0;
          if (i > data.length/2){
              rowlength -= 4;
          } else {
              rowlength += 4;
          }
          for (x=0;x<40-rowlength/2;x++){
              output += '&nbsp;';
          }
      }
      rowloc += 1;
  }
  sys.print(output);

  var server = http.createServer(function(req, res) {
    res.writeHead(200);
    res.end("<html><head><style>body{font-family:monospace;}</style></head><body>"+output+"</body></html>");
  });
  server.listen(8666);
  exec("open http://localhost:8666", puts);
});




@@ -1,12 +1,19 @@
 var 
-fs
+nsh     
  =
+ 
  req
@@ -22,22 +22,48 @@
 re('
-fs')%0Avar sys
+node-syntaxhighlighter')%0A  , fs      
  =
+ 
  req
@@ -72,361 +72,384 @@
 re('
-sy
+f
 s')%0A
-var http = require('http');%0Avar exec = require('child_process').exec;%0Afunction puts(error, stdout, stderr) %7B sys.puts(stdout) %7D%0A%0Avar output = %22%22%0A%0Afs.readFile('mondriaan.js','utf-8', function (err,data)%7B%0A  data = data.%0A    replace(/%5Cn/g,'').%0A    replace(/ /g,'').%0A    replace(/%3C/g, '&lt;').%0A    replace(/'/g, '&#039;').%0A    replace(/%22/g, '&quot;')%0A
+  , exec     =  require('child_process').exec%0A  , code     =  fs.readFileSync(__filename).toString()%0A  , style    =  'default'%0A  , htmlFile =  './mondriaan.html'%0A  ;%0A%0Avar language        =  nsh.getLanguage('js')%0A  , highlightedCode =  nsh.highlight(refactor(code), language);%0A%0A%0Afunction refactor (data)%7B%0A  data = data.%0A    replace(/%5Cn/g,'').%0A    replace(/%5B %5Ct%5D%7B2,%7D/g,' ')
 %0A  r
@@ -477,16 +477,32 @@
 c = 1;%0A%0A
+  output = %22%22;%0A%0A
   for (i
@@ -529,34 +529,8 @@
 ) %7B%0A
-      output += data%5Bi%5D;%0A%0A
     
@@ -583,13 +583,8 @@
 += '
-%3C/br%3E
 %5Cn';
@@ -802,14 +802,9 @@
 += '
-&nbsp;
+ 
 ';%0A 
@@ -818,24 +818,50 @@
   %7D%0A      %7D%0A
+      output += data%5Bi%5D;%0A%0A
       rowloc
@@ -877,17 +877,15 @@
 %7D%0A  
-sys.print
+return 
 (out
@@ -893,273 +893,635 @@
 ut);
+%0A%7D;
 %0A%0A
-  
 var 
-server = http.createServer(function(req, res) %7B%0A    res.writeHead(200);%0A    res.end(%22%3Chtml%3E%3Chead%3E%3Cstyle%3Ebody%7Bfont-family:monospace;%7D%3C/style%3E%3C/head%3E%3Cbody%3E%22+output+%22%3C/body%3E%3C/html%3E%22);%0A  %7D);%0A  server.listen(8666);%0A  exec(%22open http://localhost:8666%22, puts);%0A%7D);%0A%0A%0A
+ html = %5B%0A        '%3C!DOCTYPE HTML%3E'%0A      , '%3Chtml%3E'%0A      , '%3Chead%3E'%0A      , '   %3Cmeta http-equiv=%22content-type%22 content=%22text/html; charset=utf-8%22/%3E'%0A      , '   %3Ctitle%3EPage of Self%3C/title%3E'%0A      , ' %3Clink rel=%22stylesheet%22 href=%22./' + style + '.css%22 type=%22text/css%22 media=%22screen%22 charset=%22utf-8%22 /%3E'%0A      , ' %3Cstyle%3Ebody%7Bletter-spacing: -1px;%7D%3C/style%3E'%0A      , '%3C/head%3E'%0A      , '%3Cbody%3E'%0A      , highlightedCode%0A      , '%3C/body%3E'%0A      , '%3C/html'%0A      %5D.join('%5Cn');%0A%0Ansh.copyStyle(style, '.');%0Afs.writeFileSync(htmlFile, html);%0A%0Aconsole.log('Opening highlighted page. Using style', style);%0Aexec('open ' + htmlFile);
 %0A

replace http server with write to file and added syntax highlight