def handle_tag
@already << @m.pre_match
@rest = @m.post_match
is_closing = !!@m[1]
tag = @m[2]
@first_tag ||= tag
attributes = @m[3].to_s
is_single = false
if attributes[-1, 1] == '/'
attributes = attributes[0, attributes.size - 1]
is_single = true
end
if TO_SANITIZE.include? tag
attributes.strip!
if attributes.size > 0
@already << '<%s %s />' % [tag, attributes]
else
@already << '<%s />' % [tag]
end
elsif is_closing
if @tag_stack.empty?
error "Malformed: closing tag #{tag.inspect} in empty list"
elsif @tag_stack.last != tag
error "Malformed: tag <#{tag}> closes <#{@tag_stack.last}>"
end
close_script_style if script_style?
@already << @m.to_s
@tag_stack.pop
else
@already << @m.to_s
@tag_stack.push(tag) unless is_single
start_script_style if script_style?
end
end