class Loofah::Scrubber

A Scrubber wraps up a block (or method) that is run on an HTML node (element):

# change all <span> tags to <div> tags
span2div = Loofah::Scrubber.new do |node|
  node.name = "div" if node.name == "span"
end

Alternatively, this scrubber could have been implemented as:

class Span2Div < Loofah::Scrubber
  def scrub(node)
    node.name = "div" if node.name == "span"
  end
end
span2div = Span2Div.new

This can then be run on a document:

Loofah.html5_fragment("<span>foo</span><p>bar</p>").scrub!(span2div).to_s
# => "<div>foo</div><p>bar</p>"

Scrubbers can be run on a document in either a top-down traversal (the default) or bottom-up. Top-down scrubbers can optionally return Scrubber::STOP to terminate the traversal of a subtree.