class Loofah::Scrubbers::Whitewash
Certainly not me.
all kinds of cruft into its HTML output. Who needs that crap?
rich text editor. Microsoft’s software is famous for injecting
cut-and-pasted from Microsoft Word into a WYSIWYG editor or a
One use case for this scrubber is to clean up HTML that was
=> “ohai! <div>div with attributes</div>”
Loofah.html5_fragment(messy_markup).scrub!(:whitewash)
messy_markup = “ohai! <div id=‘foo’ class=‘bar’ style=‘margin: 10px’>div with attributes</div>”
layer of paint on top of the HTML input to make it look nice.
like to call this “whitewashing”, since it’s like putting a new
addition to doing markup-fixer-uppery and pruning unsafe tags. I:whitewash
removes all comments, styling and attributes in
=== scrub!(:whitewash)
def initialize # rubocop:disable Lint/MissingSuper
def initialize # rubocop:disable Lint/MissingSuper @direction = :top_down end
def scrub(node)
def scrub(node) case node.type when Nokogiri::XML::Node::ELEMENT_NODE if HTML5::Scrub.allowed_element?(node.name) node.attributes.each { |attr| node.remove_attribute(attr.first) } return CONTINUE if node.namespaces.empty? end when Nokogiri::XML::Node::TEXT_NODE, Nokogiri::XML::Node::CDATA_SECTION_NODE return CONTINUE end node.remove STOP end