Class: Gammo::Parser::AfterHead

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

Overview

Section 12.2.6.4.5.

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
9
10
11
12
13
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 5

def character_token(token)
  s = token.data.lstrip
  if s.length < token.data.length
    # add the initial whitespace to the current node.
    parser.add_text token.data.slice(0, token.data.length - s.length)
    halt true if s == ''
    token.data = s
  end
end

#comment_token(token) ⇒ Object



53
54
55
56
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 53

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

#default(_) ⇒ Object



63
64
65
66
67
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 63

def default(_)
  parser.parse_implied_token(Tokenizer::StartTagToken, Tags::Body, Tags::Body.to_s)
  parser.frameset_ok = true
  halt false
end

#doctype_token(token) ⇒ Object



58
59
60
61
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 58

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

#end_tag_token(token) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 41

def end_tag_token(token)
  case token.tag
  when Tags::Body, Tags::Html, Tags::Br
    # drop down to creating an implied <body> tag.
  when Tags::Template
    halt InHead.new(parser).process
  else
    # ignore the token.
    halt true
  end
end

#start_tag_token(token) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gammo/parser/insertion_mode/after_head.rb', line 15

def start_tag_token(token)
  case token.tag
  when Tags::Html then halt InBody.new(parser).process
  when Tags::Body
    parser.add_element
    parser.frameset_ok = false
    parser.insertion_mode = InBody
    halt true
  when Tags::Frameset
    parser.add_element
    parser.insertion_mode = InFrameset
    halt true
  when Tags::Base, Tags::Basefont, Tags::Bgsound, Tags::Link, Tags::Meta,
    Tags::Noframes, Tags::Script, Tags::Style, Tags::Template, Tags::Title
    parser.open_elements << parser.head
    begin
      halt InHead.new(parser).process
    ensure
      parser.open_elements.delete(parser.head)
    end
  when Tags::Head
    # ignore the token
    halt true
  end
end