Class: Gammo::Parser::BeforeHead

Inherits:
InsertionMode show all
Defined in:
lib/gammo/parser/insertion_mode/before_head.rb

Overview

Section 12.2.6.4.3

Instance Attribute Summary

Attributes inherited from InsertionMode

#parser

Instance Method Summary collapse

Methods inherited from InsertionMode

#initialize, #process

Constructor Details

This class inherits a constructor from Gammo::Parser::InsertionMode

Instance Method Details

#character_token(token) ⇒ Object



5
6
7
8
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 5

def character_token(token)
  token.data = token.data.lstrip
  halt true if token.data.length.zero?
end

#comment_token(token) ⇒ Object



33
34
35
36
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 33

def comment_token(token)
  parser.add_child(Node::Comment.new(data: token.data))
  halt true
end

#default(_) ⇒ Object



43
44
45
46
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 43

def default(_)
  parser.parse_implied_token Tokenizer::StartTagToken, Tags::Head, Tags::Head.to_s
  halt false
end

#doctype_token(token) ⇒ Object



38
39
40
41
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 38

def doctype_token(token)
  # ignore the token.
  halt true
end

#end_tag_token(token) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 22

def end_tag_token(token)
  case token.tag
  when Tags::Head, Tags::Body, Tags::Html, Tags::Br
    parser.parse_implied_token Tokenizer::StartTagToken, Tags::Head, Tags::Head.to_s
    halt false
  else
    # ignore the token.
    halt true
  end
end

#start_tag_token(token) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gammo/parser/insertion_mode/before_head.rb', line 10

def start_tag_token(token)
  case token.tag
  when Tags::Head
    parser.add_element
    parser.head = parser.top
    parser.insertion_mode = InHead
    halt true
  when Tags::Html
    halt InBody.new(parser).process
  end
end