module Wovnrb module Helpers module NokogumboHelper def parse_html(html_string, encoding = 'UTF-8') dom = if html_string.strip[0..999] =~ / 0 and doc.children.first.name = 'head' fragment << children.shift.children end # body may be next, or last. If found, take children but otherwise # ignore the body element. Also take any remaining elements, taking # care to preserve order. if children.length > 0 and doc.children.first.name = 'body' fragment << children.shift.children fragment << children elsif children.length > 0 and doc.children.last.name = 'body' body = children.pop fragment << children fragment << body.children else fragment << children end end # return result fragment end module_function :parse_html, :parse_fragment end end end