   compile: (input,cb) ->
     async.waterfall [
       @renderhbs.bind(@,input)
-      @renderMarkedDown.bind(@)
+      (input,cb) =>
+        sync (=>
+          @renderMarkedDown(input)
+        ), cb
       @applyTransforms.bind(@)
     ], cb
 

marked = require 'marked'

highlight = require "./highlight"
async = require 'async'
sync = require 'sync'
hbs = require("handlebars")
_s = require "underscore.string"

# Add the root parameter to helper options when it is invoked.
# @param root (Path) the root path for template compilation

    pipe = async.compose.apply(@,TRANSFORMERS)
    pipe(this,input,cb)

  renderMarkedDown: (input) ->
    renderer = new marked.Renderer()
    idfy = (str) -> _s.dasherize(str.toLowerCase())
    renderer.header = (text,level) ->
      "<h#{level} id='#{idfy(text)}'>#{text}</h#{level}>"
    renderer.blockcode = (code,lang) =>

      formatter = new SourceFormatter(code,lang)
      process = (cb) ->
        formatter.format({},cb)

      result = process.sync()
      # console.log "md-code", result
      @hbs.safe result

    marked input, {
      renderer: renderer
    }

module.exports = TemplateCompiler
