# File lib/haml/engine.rb, line 72
    def initialize(template, options = {})
      @options = {
        :suppress_eval => false,
        :attr_wrapper => "'",

        # Don't forget to update the docs in doc-src/HAML_REFERENCE.md
        # if you update these
        :autoclose => %w[meta img link br hr input area param col base],
        :preserve => %w[textarea pre code],

        :filename => '(haml)',
        :line => 1,
        :ugly => false,
        :format => :xhtml,
        :escape_html => false,
      }


      template = check_haml_encoding(template) do |msg, line|
        raise Haml::Error.new(msg, line)
      end

      unless ruby1_8?
        @options[:encoding] = Encoding.default_internal || template.encoding
        @options[:encoding] = "utf-8" if @options[:encoding].name == "US-ASCII"
      end
      @options.merge! options.reject {|k, v| v.nil?}
      @index = 0

      unless [:xhtml, :html4, :html5].include?(@options[:format])
        raise Haml::Error, "Invalid output format #{@options[:format].inspect}"
      end

      if @options[:encoding] && @options[:encoding].is_a?(Encoding)
        @options[:encoding] = @options[:encoding].name
      end

      # :eod is a special end-of-document marker
      @template = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
      @template_index = 0
      @to_close_stack = []
      @output_tabs = 0
      @template_tabs = 0
      @flat = false
      @newlines = 0
      @precompiled = ''
      @to_merge = []
      @tab_change  = 0

      precompile
    rescue Haml::Error => e
      if @index || e.line
        e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}"
      end
      raise
    end