var path    = require('path');
var vfs     = require('vinyl-fs');
var fs      = require('fs');
var through = require('through2');

var Super = function(options) {
  this.options = options;
  this.adapters = {};
}

Super.prototype = {
  parse: require('./lib/parse'),
  process: require('./lib/process'),
  build: require('./lib/build'),
  adapter: require('./lib/adapter')
}

var s = new Super();
s.adapter('sass', require(path.join(__dirname, 'adapters', 'sass')));
s.adapter('js', require(path.join(__dirname, 'adapters', 'js')));

module.exports = {
  init: function(options) {
    s.options = options;

    var parse = function() {
      return through.obj(function(file, enc, cb) {
        s.parse(file, function(data) {
          var tree = s.process(data);
          var ext = path.extname(file.path);

          file.path = file.path.replace(new RegExp(ext+'$'), '.html');
          file.contents = new Buffer(s.build(tree));

          if (options.dest) {
            var filePath = path.join(options.dest, path.basename(file.path));
            fs.writeFileSync(filePath, file.contents.toString());
          }
          else {
            cb(null, file);
          }
        });
      });
    }

    if (options.src) {
      vfs.src(options.src, {base: options.base}).pipe(parse());
    }
    else {
      return parse();
    }
  },
  adapter: function() {
    s.adapter.apply(s, arguments);
  },
  Super: Super
}

@@ -603,17 +603,16 @@
 ns;%0A
-%0A
     var 
 pars
@@ -607,21 +607,50 @@
     var 
-parse
+debugTree = %5B%5D;%0A%0A    var transform
  = funct
@@ -827,24 +827,155 @@
 ile.path);%0A%0A
+          // Change the extension of the incoming file to .html,%0A          // and replace the Markdown contents with rendered HTML%0A
           fi
@@ -1083,24 +1083,105 @@
 ld(tree));%0A%0A
+          if (options.debug) %7B%0A            debugTree.push(tree%5B0%5D);%0A          %7D%0A%0A
           if
@@ -1468,16 +1468,29 @@
  %7B%0A     
+ var stream =
  vfs.src
@@ -1534,17 +1534,188 @@
 ipe(
-parse());
+transform());%0A%0A      if (options.debug) %7B%0A        stream.on('finish', function() %7B%0A          fs.writeFile(options.debug, JSON.stringify(debugTree, null, '  '));%0A        %7D);%0A      %7D
 %0A   
@@ -1741,21 +1741,25 @@
  return 
-parse
+transform
 ();%0A    

Add option to output tree of all components as JSON