Class: Loofah::Scrubbers::Strip
- Inherits:
-
Loofah::Scrubber
- Object
- Loofah::Scrubber
- Loofah::Scrubbers::Strip
- Defined in:
- lib/loofah/scrubbers.rb
Overview
scrub!(:strip)
+:strip+ removes unknown/unsafe tags, but leaves behind the pristine contents:
unsafe_html = "ohai! <div>div is safe</div> <foo>but foo is <b>not</b></foo>"
Loofah.fragment(unsafe_html).scrub!(:strip)
=> "ohai! <div>div is safe</div> but foo is <b>not</b>"
Constant Summary
Constants inherited from Loofah::Scrubber
Loofah::Scrubber::CONTINUE, Loofah::Scrubber::STOP
Instance Attribute Summary
Attributes inherited from Loofah::Scrubber
Instance Method Summary collapse
-
#initialize ⇒ Strip
constructor
A new instance of Strip.
- #scrub(node) ⇒ Object
Methods inherited from Loofah::Scrubber
Constructor Details
#initialize ⇒ Strip
Returns a new instance of Strip.
97 98 99 |
# File 'lib/loofah/scrubbers.rb', line 97 def initialize @direction = :bottom_up end |
Instance Method Details
#scrub(node) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/loofah/scrubbers.rb', line 101 def scrub(node) return CONTINUE if html5lib_sanitize(node) == CONTINUE if node.children.length == 1 && node.children.first.cdata? sanitized_text = Loofah.fragment(node.children.first.to_html).scrub!(:strip).to_html node.before Nokogiri::XML::Text.new(sanitized_text, node.document) else node.before node.children end node.remove end |