module Capybara

def HTML(html) # rubocop:disable Naming/MethodName

Returns:
  • (Nokogiri::HTML::Document) - HTML document

Parameters:
  • html (String) -- The raw html
def HTML(html) # rubocop:disable Naming/MethodName
  # Nokogiri >= 1.12.0 or Nokogumbo installed and allowed for use
  html_parser, using_html5 = if defined?(Nokogiri::HTML5) && Capybara.use_html5_parsing
    [Nokogiri::HTML5, true]
  else
    [defined?(Nokogiri::HTML4) ? Nokogiri::HTML4 : Nokogiri::HTML, false]
  end
  html_parser.parse(html).tap do |document|
    document.xpath('//template').each do |template|
      # template elements content is not part of the document
      template.inner_html = ''
    end
    document.xpath('//textarea').each do |textarea|
      # The Nokogiri HTML5 parser already returns spec compliant contents
      textarea['_capybara_raw_value'] = using_html5 ? textarea.content : textarea.content.delete_prefix("\n")
    end
  end
end