 async = require 'async'
 Viz = require '../dependencies/viz/viz.js'
 plantumlAPI = require './puml'
+codeChunkAPI = require './code-chunk'
 {svgAsPngUri} = require '../dependencies/save-svg-as-png/save-svg-as-png.js'
 
 getFileExtension = (documentType)->

              width = svgElement.getBBox().width
              height = svgElement.getBBox().height

              saveSvgAsPng div.children[0], dest, {width, height}, (error)->
                cb(null, {dest, start, end, content})

        asyncFunc = helper(start, end, content)
        asyncFunctions.push asyncFunc
    else # code chunk
         # TODO: support this in the future
      null

  async.parallel asyncFunctions, (error, data)->
    # TODO: deal with error in the future.
    #
    imagePaths = []

    for d in data
      continue if !d
      {start, end, dest} = d
      imgMd = "![](#{path.relative(rootDirectoryPath, dest)})"
      imagePaths.push dest

      lines[start] = imgMd
      i = start + 1
      while i <= end
        lines[i] = null # filter out later.
        i += 1

    lines = lines.filter (line)-> line!=null
              .join('\n')


                saveSvgAsPng svgElement, dest, {}, (error)->
                  document.body.removeChild(div)
                  cb(null, {dest, start, end, content, type: 'graph'})
            else
              cb(null, null)

