lib/dryopteris/sanitize.rb in mdalessio-dryopteris-0.1.1 vs lib/dryopteris/sanitize.rb in mdalessio-dryopteris-0.1.2
- old
+ new
@@ -16,11 +16,26 @@
body_element = doc.at("/html/body")
return "" if body_element.nil?
body_element.inner_text
end
- def whitewash(string_or_io, encoding=nil)
+
+ def whitewash(string, encoding=nil)
+ return nil if string.nil?
+ return "" if string.strip.size == 0
+
+ string = "<html><body>" + string + "</body></html>"
+ doc = Nokogiri::HTML.parse(string, nil, encoding)
+ body = doc.xpath("/html/body").first
+ return "" if body.nil?
+ body.children.each do |node|
+ traverse_conditionally_top_down(node, :whitewash_node)
+ end
+ body.children.map { |x| x.to_xml }.join
+ end
+
+ def whitewash_document(string_or_io, encoding=nil)
return nil if string_or_io.nil?
return "" if string_or_io.strip.size == 0
doc = Nokogiri::HTML.parse(string_or_io, nil, encoding)
body = doc.xpath("/html/body").first
@@ -28,9 +43,10 @@
body.children.each do |node|
traverse_conditionally_top_down(node, :whitewash_node)
end
body.children.map { |x| x.to_xml }.join
end
+
def sanitize(string, encoding=nil)
return nil if string.nil?
return "" if string.strip.size == 0