Sha256: 0237c977d8c3f6a5ac754193b8b86c0f4a79623664b6c1f0ecce8a486340a87f

Contents?: true

Size: 1.91 KB

Versions: 165

Compression:

Stored size: 1.91 KB

Contents

module Nokogiri
  module HTML
    ###
    # Nokogiri lets you write a SAX parser to process HTML but get HTML
    # correction features.
    #
    # See Nokogiri::HTML::SAX::Parser for a basic example of using a
    # SAX parser with HTML.
    #
    # For more information on SAX parsers, see Nokogiri::XML::SAX
    module SAX
      ###
      # This class lets you perform SAX style parsing on HTML with HTML
      # error correction.
      #
      # Here is a basic usage example:
      #
      #   class MyDoc < Nokogiri::XML::SAX::Document
      #     def start_element name, attributes = []
      #       puts "found a #{name}"
      #     end
      #   end
      #
      #   parser = Nokogiri::HTML::SAX::Parser.new(MyDoc.new)
      #   parser.parse(File.read(ARGV[0], mode: 'rb'))
      #
      # For more information on SAX parsers, see Nokogiri::XML::SAX
      class Parser < Nokogiri::XML::SAX::Parser
        ###
        # Parse html stored in +data+ using +encoding+
        def parse_memory data, encoding = 'UTF-8'
          raise ArgumentError unless data
          return unless data.length > 0
          ctx = ParserContext.memory(data, encoding)
          yield ctx if block_given?
          ctx.parse_with self
        end

        ###
        # Parse given +io+
        def parse_io io, encoding = 'UTF-8'
          check_encoding(encoding)
          @encoding = encoding
          ctx = ParserContext.io(io, ENCODINGS[encoding])
          yield ctx if block_given?
          ctx.parse_with self
        end

        ###
        # Parse a file with +filename+
        def parse_file filename, encoding = 'UTF-8'
          raise ArgumentError unless filename
          raise Errno::ENOENT unless File.exist?(filename)
          raise Errno::EISDIR if File.directory?(filename)
          ctx = ParserContext.file(filename, encoding)
          yield ctx if block_given?
          ctx.parse_with self
        end
      end
    end
  end
end

Version data entries

165 entries across 141 versions & 14 rubygems

Version Path
nokogiri-1.10.10-x86-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.10-x64-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.10-java lib/nokogiri/html/sax/parser.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.9/lib/nokogiri/html/sax/parser.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.5/lib/nokogiri/html/sax/parser.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.1/lib/nokogiri/html/sax/parser.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.9/lib/nokogiri/html/sax/parser.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.9/lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.9 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.9-x86-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.9-x64-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.9-java lib/nokogiri/html/sax/parser.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.8/lib/nokogiri/html/sax/parser.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.5/lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.8 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.8-x86-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.8-x64-mingw32 lib/nokogiri/html/sax/parser.rb
nokogiri-1.10.8-java lib/nokogiri/html/sax/parser.rb
husc-0.2.1 vendor/bundle/gems/nokogiri-1.10.7/lib/nokogiri/html/sax/parser.rb
husc-0.2.0 vendor/bundle/gems/nokogiri-1.10.7/lib/nokogiri/html/sax/parser.rb