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.
15 16 17 |
# File 'lib/json/ld/html/nokogiri.rb', line 15 def self.library :nokogiri end |
Instance Method Details
#initialize_html_nokogiri(input, _options = {}) ⇒ NodeProxy Also known as: initialize_html
Initializes the underlying XML library.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/json/ld/html/nokogiri.rb', line 133 def initialize_html_nokogiri(input, = {}) require 'nokogiri' unless defined?(::Nokogiri) doc = case input when ::Nokogiri::HTML::Document, ::Nokogiri::XML::Document input else begin input = input.read if input.respond_to?(:read) ::Nokogiri::HTML5(input.force_encoding('utf-8'), max_parse_errors: 1000) rescue LoadError, NoMethodError ::Nokogiri::HTML.parse(input, base_uri.to_s, 'utf-8') end end NodeProxy.new(doc.root) if doc&.root end |