 HEREDOC       = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/
 OPERATOR      = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/
 WHITESPACE    = /^([ \t]+)/
-COMMENT       = /^(\s*###(?!#)([\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
+COMMENT       = /^(([ \t]*\n)*([ \t]*)###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
 CODE          = /^((-|=)>)/
 MULTI_DENT    = /^((\n([ \t]*))+)(\.)?/
 LAST_DENTS    = /\n([ \t]*)/g

    return false unless match = @chunk.match(COMMENT)
    @line += count match[1], "\n"
    @i += match[1].length
    if match[2]
      @token 'HERECOMMENT', @sanitizeHeredoc match[2], herecomment: true
      @token 'TERMINATOR', '\n'
    true


  # Sanitize a heredoc or herecomment by escaping internal double quotes and
  # erasing all external indentation on the left-hand side.
  sanitizeHeredoc: (doc, options) ->
    indent = options.indent or ''
    return doc if options.herecomment and not include doc, '\n'
    unless options.herecomment
      while match = HEREDOC_INDENT.exec(doc)
        attempt = if match[2]? then match[2] else match[3]
        indent = attempt if not indent or attempt.length < indent.length
    doc = doc.replace(new RegExp("^" + indent, 'gm'), '')
    return doc if options.herecomment
    doc.replace(MULTILINER, "\\n")
       .replace(new RegExp(options.quote, 'g'), "\\#{options.quote}")
