   insert = (data, root) ->
     tag = data[0][0]
 
-    headerId = getHeaderId data
     childTag = _.last _.pluck root.children, 'tag'
 
     if _.isEmpty(root.children) or compareTags(tag, childTag) >= 0

    return root


  # Returns header id for a region (accessible in the template).
  # Either you can specify the id in the Markdown file or it will take the
  # heading text and slugify it.
  getHeaderId = (data) ->
    text = _.last data[0]
    {id_pattern} = _options
    match = text.match id_pattern

    if match
      # Strip the ID pattern.
      data[0][data[0].length - 1] = _.trim text.replace(id_pattern, '')
      headerId = match[1]

    # Slugify the header text.
    headerId or= _(data[0]).chain().last().slugify().value().toLowerCase()

    return headerId


  grunt.registerMultiTask 'md_to_html', 'Transmogrify your MD into HTML.', ->

    # Default options.
    _options = @options
      id_pattern: /{(.+)}/
      tags: ['h1', 'h2', 'h3']

    _.each @files, ({src, template, dest}) =>

      files = _.filter src, (filepath) ->
        if not grunt.file.exists filepath

  beautifyHTML = require('js-beautify').html
  Entities = require('html-entities').AllHtmlEntities
  {decode} = new Entities()
  path = require 'path'
  mkdirp = require 'mkdirp'


  # Global options hash.
