Sha256: 6696ee471c412903e88d570a5d62e597e6ba86ac8384b5ff5291978cd5526985

Contents?: true

Size: 1.93 KB

Versions: 61

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true
module Nokogiri
  module HTML4
    ###
    # Nokogiri lets you write a SAX parser to process HTML but get HTML correction features.
    #
    # See Nokogiri::HTML4::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::HTML4::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

61 entries across 61 versions & 4 rubygems

Version Path
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/html4/sax/parser.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/html4/sax/parser.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-x86_64-linux lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-x86_64-darwin lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-x86-mingw32 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-x86-linux lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-x64-mingw32 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-java lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.5-arm64-darwin lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-x86_64-linux lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-x86_64-darwin lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-x86-mingw32 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-x86-linux lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-x64-mingw32 lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-java lib/nokogiri/html4/sax/parser.rb
nokogiri-1.12.4-arm64-darwin lib/nokogiri/html4/sax/parser.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.12.3-x86_64-linux/lib/nokogiri/html4/sax/parser.rb