class Hpricot::Elem

def attributes

def attributes
  Attributes.new self
end

def attributes_as_html

def attributes_as_html
  if raw_attributes
    raw_attributes.map do |aname, aval|
      " #{aname}" +
        (aval ? "=#{html_quote aval}" : "")
    end.join
  end
end

def empty?; children.nil? or children.empty? end

def empty?; children.nil? or children.empty? end

def initialize tag, attrs = nil, children = nil, etag = nil

def initialize tag, attrs = nil, children = nil, etag = nil
  self.name, self.raw_attributes, self.children, self.etag =
    tag, attrs, children, etag
end

def inspect_tree(depth = 0)

def inspect_tree(depth = 0)
  %{#{" " * depth}} + name + "\n" +
    (children ? children.map { |x| x.inspect_tree(depth + 1) }.join : "")
end

def output(out, opts = {})

def output(out, opts = {})
  out <<
    if_output(opts) do
      "<#{name}#{attributes_as_html}" +
        ((empty? and not etag) ? " /" : "") +
        ">"
    end
  if children
    children.each { |n| n.output(out, opts) }
  end
  if opts[:preserve]
    out << etag if etag
  elsif etag or !empty?
    out << "</#{name}>"
  end
  out
end

def pathname; self.name end

def pathname; self.name end

def pretty_print(q)

def pretty_print(q)
  if empty?
    q.group(1, '{emptyelem', '}') {
      q.breakable; pretty_print_stag q
    }
  else
    q.group(1, "{elem", "}") {
      q.breakable; pretty_print_stag q
      if children
        children.each {|elt| q.breakable; q.pp elt }
      end
      if etag
        q.breakable; q.text etag
      end
    }
  end
end

def pretty_print_stag(q)

def pretty_print_stag(q)
  q.group(1, '<', '>') {
    q.text name
    if raw_attributes
      raw_attributes.each {|n, t|
        q.breakable
        if t
          q.text "#{n}=\"#{Hpricot.uxs(t)}\""
        else
          q.text n
        end
      }
    end
  }
end

def to_plain_text

def to_plain_text
  if self.name == 'br'
    "\n"
  elsif self.name == 'p'
    "\n\n" + super + "\n\n"
  elsif self.name == 'a' and self.has_attribute?('href')
    "#{super} [#{self['href']}]"
  elsif self.name == 'img' and self.has_attribute?('src')
    "[img:#{self['src']}]"
  else
    super
  end
end