module Loofah::ScrubBehavior
Mixes scrub!
into Document, DocumentFragment, Node and NodeSet.
Traverse the document or fragment, invoking the scrubber
on
each node.
scrubber
must either be one of the symbols representing the
built-in scrubbers (see Scrubbers), or a Scrubber instance.
span2div = Loofah::Scrubber.new do |node| node.name = "div" if node.name == "span" end Loofah.html5_fragment("<span>foo</span><p>bar</p>").scrub!(span2div).to_s # => "<div>foo</div><p>bar</p>"
or
unsafe_html = "ohai! <div>div is safe</div> <script>but script is not</script>" Loofah.html5_fragment(unsafe_html).scrub!(:strip).to_s # => "ohai! <div>div is safe</div> "
Note that this method is called implicitly from the shortcuts Loofah.scrub_html5_fragment et al.
Please see Scrubber for more information on implementation and traversal, and README.rdoc for more example usage.