class Nokogiri::HTML5::Document

Since v1.12.0

💡 HTML5 functionality is not available when running JRuby.

Public Class Methods

parse(string_or_io, url = nil, encoding = nil, **options) { |options| ... } click to toggle source
# File lib/nokogiri/html5/document.rb, line 28
def self.parse(string_or_io, url = nil, encoding = nil, **options, &block)
  yield options if block
  string_or_io = "" unless string_or_io

  if string_or_io.respond_to?(:encoding) && string_or_io.encoding.name != "ASCII-8BIT"
    encoding ||= string_or_io.encoding.name
  end

  if string_or_io.respond_to?(:read) && string_or_io.respond_to?(:path)
    url ||= string_or_io.path
  end
  unless string_or_io.respond_to?(:read) || string_or_io.respond_to?(:to_str)
    raise ArgumentError, "not a string or IO object"
  end
  do_parse(string_or_io, url, encoding, options)
end
read_io(io, url = nil, encoding = nil, **options) click to toggle source
# File lib/nokogiri/html5/document.rb, line 45
def self.read_io(io, url = nil, encoding = nil, **options)
  raise ArgumentError, "io object doesn't respond to :read" unless io.respond_to?(:read)
  do_parse(io, url, encoding, options)
end
read_memory(string, url = nil, encoding = nil, **options) click to toggle source
# File lib/nokogiri/html5/document.rb, line 50
def self.read_memory(string, url = nil, encoding = nil, **options)
  raise ArgumentError, "string object doesn't respond to :to_str" unless string.respond_to?(:to_str)
  do_parse(string, url, encoding, options)
end

Public Instance Methods

fragment(tags = nil) click to toggle source
# File lib/nokogiri/html5/document.rb, line 55
def fragment(tags = nil)
  DocumentFragment.new(self, tags, root)
end
to_xml(options = {}, &block) click to toggle source
# File lib/nokogiri/html5/document.rb, line 59
def to_xml(options = {}, &block)
  # Bypass XML::Document#to_xml which doesn't add
  # XML::Node::SaveOptions::AS_XML like XML::Node#to_xml does.
  XML::Node.instance_method(:to_xml).bind(self).call(options, &block)
end
xpath_doctype() → Nokogiri::CSS::XPathVisitor::DoctypeConfig click to toggle source
Returns

The document type which determines CSS-to-XPath translation.

See XPathVisitor for more information.

# File lib/nokogiri/html5/document.rb, line 71
def xpath_doctype
  Nokogiri::CSS::XPathVisitor::DoctypeConfig::HTML5
end