module Hpricot class Elements def strip each { |x| x.strip } end def strip_attributes(safe=[], patterns={}) each { |x| x.strip_attributes(safe, patterns) } end end class Elem def strip parent.replace_child self, Hpricot.make(inner_html) unless parent.nil? end def strip_attributes(safe=[], patterns={}) attributes.each { |atr| pat = patterns[atr[0].to_sym] || '' remove_attribute(atr[0]) unless safe.include?(atr[0]) && atr[1].match(pat) } unless attributes.nil? end end end