Module: JSON::LD::API::Nokogiri
- Defined in:
- lib/json/ld/html/nokogiri.rb
Overview
Nokogiri implementation of an HTML parser.
Defined Under Namespace
Classes: NodeProxy, NodeSetProxy
Class Method Summary collapse
-
.library ⇒ Symbol
Returns the name of the underlying XML library.
Instance Method Summary collapse
-
#initialize_html_nokogiri(input, options = {}) ⇒ NodeProxy
(also: #initialize_html)
Initializes the underlying XML library.
Class Method Details
.library ⇒ Symbol
Returns the name of the underlying XML library.
12 13 14 |
# File 'lib/json/ld/html/nokogiri.rb', line 12 def self.library :nokogiri end |
Instance Method Details
#initialize_html_nokogiri(input, options = {}) ⇒ NodeProxy Also known as: initialize_html
Initializes the underlying XML library.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/json/ld/html/nokogiri.rb', line 132 def initialize_html_nokogiri(input, = {}) require 'nokogiri' unless defined?(::Nokogiri) doc = case input when ::Nokogiri::HTML::Document, ::Nokogiri::XML::Document input else begin require 'nokogumbo' unless defined?(::Nokogumbo) input = input.read if input.respond_to?(:read) ::Nokogiri::HTML5(input.dup.force_encoding('utf-8'), max_parse_errors: 1000) rescue LoadError ::Nokogiri::HTML.parse(input, 'utf-8') end end NodeProxy.new(doc.root) if doc && doc.root end |