def clean!(html)
fragment = Nokogiri::HTML::DocumentFragment.parse(html)
clean_node!(fragment)
output_method_params = {:encoding => @config[:output_encoding], :indent => 0}
if @config[:output] == :xhtml
output_method = fragment.method(:to_xhtml)
output_method_params[:save_with] = Nokogiri::XML::Node::SaveOptions::AS_XHTML
elsif @config[:output] == :html
output_method = fragment.method(:to_html)
else
raise Error, "unsupported output format: #{@config[:output]}"
end
result = output_method.call(output_method_params)
return result == html ? nil : html[0, html.length] = result
end