       childHTML = ""
     
     if root.isBlock
+      # We're adding `body` for blocks because we don't want to include 
+      # the block element itself (which would happen if we included `content`).
       root.html = (root.body or '') + childHTML
     else
       root.html = (root.content or '') + childHTML

    res.push _.rest(pathToRoot)


  splitIntoMultipleFiles = (data, tpl, dest, ext) ->
    leaves = []
    getDataLeaves data, [], leaves

    tmp = []

    # Add the non-leaf paths to the mix as well (so that we have links to
    # e.g. foo/bar, i.e., the "section overview page").
    leaves = _.union leaves, (_.initial(p) for p in leaves)

    for leavePath in leaves when leavePath.length > 0
      parts = _.union([dest], _.pluck(leavePath, 'id'))
      leaveDest = path.join.apply @, parts
      leaveDest = "#{leaveDest}#{ext}"

      grunt.log.debug 'mkdirp', path.dirname(leaveDest)
      grunt.log.debug 'section',_.pluck(leavePath, 'id'), _.last(leavePath)

      if not _.last(leavePath).body
        grunt.log.debug "skipping ", _.pluck(leavePath, 'id'), ": no body"
        continue

      mkdirp.sync path.dirname(leaveDest)

      grunt.file.copy tpl, leaveDest,
        process: (contents, path) ->
          html = grunt.template.process contents, data: _.extend({
              section: _.last(leavePath)
              ids: _.pluck(leavePath, 'id')
              all: data
              root: leavePath[0]
            }, _options.data)
          # Pretty print the html.
          return if _options.pretty then beautifyHTML(html) else html

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


