Module: JSON::LD::API::Nokogiri

Defined in:
vendor/bundler/ruby/2.6.0/bundler/gems/json-ld-94ee7791d19f/lib/json/ld/html/nokogiri.rb

Overview

Nokogiri implementation of an HTML parser.

Defined Under Namespace

Classes: NodeProxy, NodeSetProxy

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.librarySymbol

Returns the name of the underlying XML library.

Returns:



12
13
14
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/json-ld-94ee7791d19f/lib/json/ld/html/nokogiri.rb', line 12

def self.library
  :nokogiri
end

Instance Method Details

#initialize_html(input, options = {}) ⇒ NodeProxy

Initializes the underlying XML library.

Parameters:

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/json-ld-94ee7791d19f/lib/json/ld/html/nokogiri.rb', line 132

def initialize_html(input, options = {})
  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, base_uri.to_s, 'utf-8')
    end
  end

  NodeProxy.new(doc.root) if doc && doc.root
end