class CodeRay::Encoders::HTML

def setup options

def setup options
  super
  
  if options[:wrap] || options[:line_numbers]
    @real_out = @out
    @out = ''
  end
  
  @HTML_ESCAPE = HTML_ESCAPE.dup
  @HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
  
  @opened = []
  @last_opened = nil
  @css = CSS.new options[:style]
  
  hint = options[:hint]
  if hint && ![:debug, :info, :info_long].include?(hint)
    raise ArgumentError, "Unknown value %p for :hint; \
      expected :info, :info_long, :debug, false, or nil." % hint
  end
  
  css_classes = TokenKinds
  case options[:css]
  when :class
    @span_for_kind = Hash.new do |h, k|
      if k.is_a? ::Symbol
        kind = k_dup = k
      else
        kind = k.first
        k_dup = k.dup
      end
      if kind != :space && (hint || css_class = css_classes[kind])
        title = HTML.token_path_to_hint hint, k if hint
        css_class ||= css_classes[kind]
        h[k_dup] = "<span#{title}#{" class=\"#{css_class}\"" if css_class}>"
      else
        h[k_dup] = nil
      end
    end
  when :style
    @span_for_kind = Hash.new do |h, k|
      kind = k.is_a?(Symbol) ? k : k.first
      h[k.is_a?(Symbol) ? k : k.dup] =
        if kind != :space && (hint || css_classes[kind])
          title = HTML.token_path_to_hint hint, k if hint
          style = @css.get_style Array(k).map { |c| css_classes[c] }
          "<span#{title}#{" style=\"#{style}\"" if style}>"
        end
    end
  else
    raise ArgumentError, "Unknown value %p for :css." % options[:css]
  end
  
  @set_last_opened = options[:hint] || options[:css] == :style
end