diff --git a/lib/html_to_plain_text.rb b/lib/html_to_plain_text.rb
index 1001f40c..f0040d06 100644
--- a/lib/html_to_plain_text.rb
+++ b/lib/html_to_plain_text.rb
@@ -10,7 +10,7 @@ module HtmlToPlainText
doc = Nokogiri::HTML.fragment(cleaned)
- doc.css('script').each(&:remove)
+ doc.xpath('.//script').each(&:remove)
result = process_nodes(doc, line_length)
@@ -33,12 +33,9 @@ module HtmlToPlainText
result = +''
node.children.each do |child|
- case child
- when Nokogiri::XML::Text
+ if child.text? || child.cdata?
result << child.text
- when Nokogiri::XML::Comment
- next
- when Nokogiri::XML::Element
+ elsif child.element?
result << process_element(child, line_length)
end
end