module JSON::LD::API::Nokogiri

Nokogiri implementation of an HTML parser.

@see nokogiri.org/

Public Class Methods

library() click to toggle source

Returns the name of the underlying XML library.

@return [Symbol]

# File lib/json/ld/html/nokogiri.rb, line 12
def self.library
  :nokogiri
end

Public Instance Methods

initialize_html(input, options = {})
initialize_html_nokogiri(input, options = {}) click to toggle source

Initializes the underlying XML library.

@param [Hash{Symbol => Object}] options @return [NodeProxy] of root element

# 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
      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 && doc.root
end
Also aliased as: initialize_html