I noticed something strange using Nokogiri recently. All of the HTML I had been parsing had been given start and end and
The problem occurs because you're using the wrong method in Nokogiri to parse your content.
require 'nokogiri'
doc = Nokogiri::HTML('foobar
')
puts doc.to_html
# >>
# >> foobar
Rather than using HTML which results in a complete document, use HTML.fragment, which tells Nokogiri you only want the fragment parsed:
doc = Nokogiri::HTML.fragment('foobar
')
puts doc.to_html
# >> foobar