Class: Gammo::Parser::InHead

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

Overview

Section 12.2.6.4.4.

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/in_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



83
84
85
86
# File 'lib/gammo/parser/insertion_mode/in_head.rb', line 83

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

#default(_) ⇒ Object



92
93
94
95
96
# File 'lib/gammo/parser/insertion_mode/in_head.rb', line 92

def default(_)
  parser.open_elements.pop
  parser.insertion_mode = AfterHead
  halt false
end

#doctype_token(token) ⇒ Object



88
89
90
# File 'lib/gammo/parser/insertion_mode/in_head.rb', line 88

def doctype_token(token)
  halt true
end

#end_tag_token(token) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gammo/parser/insertion_mode/in_head.rb', line 54

def end_tag_token(token)
  case token.tag
  when Tags::Head
    parser.open_elements.pop
    parser.insertion_mode = AfterHead
    halt true
  when Tags::Body, Tags::Html, Tags::Br
    parser.parse_implied_token(Tokenizer::EndTagToken, Tags::Head, Tags::Head.to_s)
    halt false
  when Tags::Template
    halt true if !parser.open_elements.any? { |oe| oe.tag == Tags::Template }
    # remove this divergence from the HTML5 spec.
    parser.generate_implied_end_tags
    parser.open_elements.reverse_each_with_index do |open_element, index|
      if !open_element.namespace && open_element.tag == Tags::Template
        parser.open_elements = parser.open_elements.slice(0, index)
        break
      end
    end
    parser.clear_active_formatting_elements
    parser.template_stack.pop
    parser.reset_insertion_mode
    halt true
  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
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gammo/parser/insertion_mode/in_head.rb', line 15

def start_tag_token(token)
  case token.tag
  when Tags::Html
    halt InBody.new(parser).process
  when Tags::Base, Tags::Basefont, Tags::Bgsound, Tags::Link, Tags::Meta
    parser.add_element
    parser.open_elements.pop
    parser.acknowledge_self_closing_tag
    halt true
  when Tags::Noscript
    if parser.scripting?
      parser.parse_generic_raw_text_element
      halt true
    end
    parser.add_element
    parser.insertion_mode = InHeadNoscript
    parser.tokenizer.next_is_not_raw_text!
    halt true
  when Tags::Script, Tags::Title
    parser.add_element
    parser.set_original_insertion_mode
    parser.insertion_mode = Text
    halt true
  when Tags::Noframes, Tags::Style
    parser.parse_generic_raw_text_element
    halt true
  when Tags::Head
    # ignore the token
    halt true
  when Tags::Template
    parser.add_element
    parser.active_formatting_elements << Node::DEFAULT_SCOPE_MARKER
    parser.frameset_ok = false
    parser.insertion_mode = InTemplate
    parser.template_stack << InTemplate
    halt true
  end
end