       # changing data object.
       getHTML = (data) -> _.union(['html'], JSON.parse JSON.stringify data)
 
+      metadata = getMetadata data
+
       root.children.push
-        id: headerId
+        id: metadata.id
+        metadata: metadata
         content: markdown.renderJsonML(getHTML data)
         header: markdown.renderJsonML(getHTML [data[0]])
         body: markdown.renderJsonML(getHTML _.rest(data))

#
# grunt-md-templator
# https://github.com/realyze/grunt-md-templator
#
# Copyright (c) 2013 Tomas Brambora
# Licensed under the MIT license.

    return root


  # Returns metadata for a region (accessible in the template).
  getMetadata = (data) ->
    grunt.log.debug 'data', data

    text = _.last data[0]
    {metadata_pattern} = _options
    match = text.match metadata_pattern

    metadata = {}

    grunt.log.debug 'match', text, match

    if match
      # Strip the metadata pattern.
      data[0][data[0].length - 1] = _.trim text.replace(metadata_pattern, '')
      metadata = JSON.parse match[1]

    metadata.id or= _(data[0]).chain().last().slugify().value().toLowerCase()

    grunt.log.debug 'meatadata', metadata

    return metadata


  grunt.registerMultiTask 'markdown_jade', 'Turn markdown & template into HTML.', ->

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

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

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