Class: Nokogiri::HTML::SAX::ParserContext

Inherits:
XML::SAX::ParserContext show all
Defined in:
lib/nokogiri/html/sax/parser_context.rb,
lib/nokogiri/ffi/html/sax/parser_context.rb,
ext/nokogiri/html_sax_parser_context.c

Overview

Context for HTML SAX parsers. This class is usually not instantiated by the user. Instead, you should be looking at Nokogiri::HTML::SAX::Parser

Instance Attribute Summary collapse

Attributes inherited from XML::SAX::ParserContext

#reader_callback

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XML::SAX::ParserContext

io, #replace_entities, #replace_entities=

Instance Attribute Details

#cstructObject

Returns the value of attribute cstruct.



6
7
8
# File 'lib/nokogiri/ffi/html/sax/parser_context.rb', line 6

def cstruct
  @cstruct
end

Class Method Details

.file(filename, encoding) ⇒ Object



43
44
45
46
47
48
# File 'ext/nokogiri/html_sax_parser_context.c', line 43

def self.file filename, encoding
  ctx = LibXML.htmlCreateFileParserCtxt filename, encoding
  pc = allocate
  pc.cstruct = LibXML::XmlParserContext.new ctx
  pc
end

.memory(data, encoding) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'ext/nokogiri/html_sax_parser_context.c', line 16

def self.memory data, encoding
  raise ArgumentError unless data
  raise "data cannot be empty" unless data.length > 0

  ctx = LibXML.htmlCreateMemoryParserCtxt data, data.length
  pc = allocate
  pc.cstruct = LibXML::XmlParserContext.new ctx
  if encoding
    enc = LibXML.xmlFindCharEncodingHandler(encoding)
    if !enc.null?
      LibXML.xmlSwitchToEncoding(ctx, enc)
    end
  end
  pc
end

.new(thing, encoding = 'UTF-8') ⇒ Object



9
10
11
12
# File 'lib/nokogiri/html/sax/parser_context.rb', line 9

def self.new thing, encoding = 'UTF-8'
  [:read, :close].all? { |x| thing.respond_to?(x) } ?  super :
    memory(thing, encoding)
end

Instance Method Details

#parse_with(sax_handler) ⇒ Object



52
53
54
# File 'ext/nokogiri/html_sax_parser_context.c', line 52

def parse_with sax_handler, type = :html
  super
end