Class: Nokogiri::HTML5::Document

Inherits:
Nokogiri::HTML::Document show all
Defined in:
lib/nokogiri/html5/document.rb,
ext/nokogiri/gumbo.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Nokogiri::XML::Document

Class Method Details

.parse(string_or_io, url = nil, encoding = nil, **options) {|options| ... } ⇒ Object

Yields:

  • (options)

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nokogiri/html5/document.rb', line 21

def self.parse(string_or_io, url = nil, encoding = nil, **options, &block)
  yield options if block_given?
	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.new("not a string or IO object")
  end
  do_parse(string_or_io, url, encoding, options)
end

.read_io(io, url = nil, encoding = nil, **options) ⇒ Object

Raises:

  • (ArgumentError)

38
39
40
41
# File 'lib/nokogiri/html5/document.rb', line 38

def self.read_io(io, url = nil, encoding = nil, **options)
  raise ArgumentError.new("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) ⇒ Object

Raises:

  • (ArgumentError)

43
44
45
46
# File 'lib/nokogiri/html5/document.rb', line 43

def self.read_memory(string, url = nil, encoding = nil, **options)
  raise ArgumentError.new("string object doesn't respond to :to_str") unless string.respond_to?(:to_str)
  do_parse(string, url, encoding, options)
end

Instance Method Details

#fragment(tags = nil) ⇒ Object


48
49
50
# File 'lib/nokogiri/html5/document.rb', line 48

def fragment(tags = nil)
  DocumentFragment.new(self, tags, self.root)
end

#to_xml(options = {}, &block) ⇒ Object


52
53
54
55
56
# File 'lib/nokogiri/html5/document.rb', line 52

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