module Nokogiri

def self.jruby? # :nodoc:

:nodoc:
def self.jruby? # :nodoc:
  VersionInfo.instance.jruby?
end

def self.uses_libxml? # :nodoc:

:nodoc:
def self.uses_libxml? # :nodoc:
  VersionInfo.instance.libxml2?
end

def HTML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block

Parse HTML. Convenience method for Nokogiri::HTML::Document.parse
##
def HTML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block
  Nokogiri::HTML::Document.parse(thing, url, encoding, options, &block)
end

def Slop(*args, &block)


assert_equal('second', doc.html.body.p[1].text)
eohtml


second


first




doc = Nokogiri::Slop(<<-eohtml)

or XPath. For example:
implements method_missing such that methods may be used instead of CSS
Parse a document and add the Slop decorator. The Slop decorator
##
def Slop(*args, &block)
  Nokogiri(*args, &block).slop!
end

def XML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block

Parse XML. Convenience method for Nokogiri::XML::Document.parse
##
def XML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block
  Nokogiri::XML::Document.parse(thing, url, encoding, options, &block)
end

def XSLT stylesheet, modules = {}


xslt = Nokogiri::XSLT(File.read(ARGV[0]))

Example:

Create a Nokogiri::XSLT::Stylesheet with +stylesheet+.
##
def XSLT stylesheet, modules = {}
  XSLT.parse(stylesheet, modules)
end

def install_default_aliases

def install_default_aliases
  # Make sure to support some popular encoding aliases not known by
  # all iconv implementations.
  {
    'Windows-31J' => 'CP932',	# Windows-31J is the IANA registered name of CP932.
  }.each { |alias_name, name|
    EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
  }
end

def make input = nil, opts = {}, &blk

Create a new Nokogiri::XML::DocumentFragment
##
def make input = nil, opts = {}, &blk
  if input
    Nokogiri::HTML.fragment(input).children.first
  else
    Nokogiri(&blk)
  end
end

def parse string, url = nil, encoding = nil, options = nil

Parse an HTML or XML document. +string+ contains the document.
##
def parse string, url = nil, encoding = nil, options = nil
  if string.respond_to?(:read) ||
      /^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
    # Expect an HTML indicator to appear within the first 512
    # characters of a document. (<?xml ?> + <?xml-stylesheet ?>
    # shouldn't be that long)
    Nokogiri.HTML(string, url, encoding,
      options || XML::ParseOptions::DEFAULT_HTML)
  else
    Nokogiri.XML(string, url, encoding,
      options || XML::ParseOptions::DEFAULT_XML)
  end.tap { |doc|
    yield doc if block_given?
  }
end