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)

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.

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:


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, 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, 'utf-8')
    end
  end

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