Class: Mullet::HTML::Parser::SimpleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/mullet/html/parser/simple_parser.rb

Overview

SAX parser that reports elements in the order they appear in the input. Does not move elements to another parent.

Constant Summary collapse

IMPLICIT_END_TAG_NS_URI =

special namespace URI indicating parser generated an implicit end tag

'http://pukkaone.github.com/mullet/end-tag'

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ SimpleParser

Constructor

Parameters:



18
19
20
# File 'lib/mullet/html/parser/simple_parser.rb', line 18

def initialize(handler)
  @handler = handler
end

Instance Method Details

#parse(input) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mullet/html/parser/simple_parser.rb', line 22

def parse(input)
  @open_element = nil
  @handler.start_document()

  tokenizer = Tokenizer.new(input)
  tokenizer.each do |token|
    case token[:type]
    when :Doctype
      doctype(token[:name], token[:publicId], token[:systemId])
    when :StartTag
      start_tag(token[:name], token[:data])
    when :EndTag
      end_tag(token[:name])
    when :Characters, :SpaceCharacters
      characters(token[:data])
    when :CDATA
      cdata(token[:data])
    when :Comment
      comment(token[:data])
    end
  end

  @handler.end_document()
end