lib/roadie/markup_improver.rb in roadie-3.5.0 vs lib/roadie/markup_improver.rb in roadie-3.5.1

- old
+ new

@@ -23,10 +23,11 @@ end # @return [nil] passed DOM will be mutated def improve ensure_doctype_present + ensure_html_element_present head = ensure_head_element_present ensure_declared_charset head end protected @@ -44,9 +45,15 @@ # JRuby up to at least 1.6.0 has a bug where the doctype of a document cannot be changed. # See https://github.com/sparklemotion/nokogiri/issues/984 def uses_buggy_jruby? # No reason to check for version yet since no existing version has a fix. defined?(JRuby) + end + + def ensure_html_element_present + return if dom.at_xpath('html') + html = Nokogiri::XML::Node.new 'html', dom + dom << html end def ensure_head_element_present if (head = dom.at_xpath('html/head')) head