Class: Nokogiri::HTML5::Document

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

Overview

Note:

HTML5 functionality is not available when running JRuby.

Since:

  • v1.12.0

Constant Summary

Constants inherited from XML::Document

XML::Document::NCNAME_CHAR, XML::Document::NCNAME_RE, XML::Document::NCNAME_START_CHAR

Constants inherited from XML::Node

XML::Node::ATTRIBUTE_DECL, XML::Node::ATTRIBUTE_NODE, XML::Node::CDATA_SECTION_NODE, XML::Node::COMMENT_NODE, XML::Node::DOCB_DOCUMENT_NODE, XML::Node::DOCUMENT_FRAG_NODE, XML::Node::DOCUMENT_NODE, XML::Node::DOCUMENT_TYPE_NODE, XML::Node::DTD_NODE, XML::Node::ELEMENT_DECL, XML::Node::ELEMENT_NODE, XML::Node::ENTITY_DECL, XML::Node::ENTITY_NODE, XML::Node::ENTITY_REF_NODE, XML::Node::HTML_DOCUMENT_NODE, XML::Node::NAMESPACE_DECL, XML::Node::NOTATION_NODE, XML::Node::PI_NODE, XML::Node::TEXT_NODE, XML::Node::XINCLUDE_END, XML::Node::XINCLUDE_START

Constants included from XML::Searchable

XML::Searchable::LOOKS_LIKE_XPATH

Instance Attribute Summary

Attributes inherited from XML::Document

#errors, #namespace_inheritance

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Nokogiri::HTML4::Document

#meta_encoding, #meta_encoding=, new, #serialize, #title, #title=, #type

Methods inherited from XML::Document

#add_child, #canonicalize, #collect_namespaces, #create_cdata, #create_comment, #create_element, #create_entity, #create_text_node, #decorate, #decorators, #document, #dup, #encoding, #encoding=, #initialize, #name, #namespaces, new, #remove_namespaces!, #root, #root=, #slop!, #to_java, #url, #validate, #version, wrap

Methods inherited from XML::Node

#<<, #<=>, #==, #>, #[], #[]=, #accept, #add_child, #add_class, #add_namespace_definition, #add_next_sibling, #add_previous_sibling, #after, #ancestors, #append_class, #attribute, #attribute_nodes, #attribute_with_ns, #attributes, #before, #blank?, #canonicalize, #cdata?, #child, #children, #children=, #classes, #comment?, #content, #content=, #create_external_subset, #create_internal_subset, #css_path, #decorate!, #default_namespace=, #description, #do_xinclude, #document, #document?, #dup, #each, #element?, #element_children, #encode_special_chars, #external_subset, #first_element_child, #fragment?, #html?, #initialize, #inner_html, #inner_html=, #internal_subset, #key?, #keys, #kwattr_add, #kwattr_append, #kwattr_remove, #kwattr_values, #lang, #lang=, #last_element_child, #line, #line=, #matches?, #namespace, #namespace=, #namespace_definitions, #namespace_scopes, #namespaced_key?, #namespaces, #native_content=, new, #next_element, #next_sibling, #node_name, #node_name=, #node_type, #parent, #parent=, #parse, #path, #pointer_id, #prepend_child, #previous_element, #previous_sibling, #processing_instruction?, #read_only?, #remove_attribute, #remove_class, #replace, #serialize, #swap, #text?, #to_html, #to_s, #to_xhtml, #traverse, #unlink, #value?, #values, #wrap, #write_html_to, #write_to, #write_xhtml_to, #write_xml_to, #xml?

Methods included from XML::Searchable

#at, #at_css, #at_xpath, #css, #search, #xpath

Methods included from XML::PP::Node

#inspect, #pretty_print

Methods included from Node

#inner_html, #write_to

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)

Since:

  • v1.12.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nokogiri/html5/document.rb', line 25

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)

Since:

  • v1.12.0



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

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)

Since:

  • v1.12.0



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

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

Since:

  • v1.12.0



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

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

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

Since:

  • v1.12.0



56
57
58
59
60
# File 'lib/nokogiri/html5/document.rb', line 56

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