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

Instance Method Summary collapse

Class Method Details

.librarySymbol

Returns the name of the underlying XML library.

Returns:

  • (Symbol)


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.

Parameters:

  • options (Hash{Symbol => Object})

Returns:



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, _options = {})
  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