Class: HTML5::InHeadPhase

Inherits:
Phase
  • Object
show all
Defined in:
lib/html5/html5parser/in_head_phase.rb

Instance Method Summary collapse

Methods inherited from Phase

#assert, end_tag_handlers, handle_end, handle_start, #in_scope?, #initialize, #processComment, #processDoctype, #processEndTag, #processSpaceCharacters, #processStartTag, #remove_open_elements_until, #startTagHtml, start_tag_handlers, tag_handlers

Constructor Details

This class inherits a constructor from HTML5::Phase

Instance Method Details

#anything_elseObject



118
119
120
121
122
123
124
# File 'lib/html5/html5parser/in_head_phase.rb', line 118

def anything_else
  if @tree.open_elements.last.name == 'head'
    endTagHead('head')
  else
    @parser.phase = @parser.phases[:afterHead]
  end
end

#endTagHead(name) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/html5/html5parser/in_head_phase.rb', line 92

def endTagHead(name)
  if @tree.open_elements.last.name == 'head'
    @tree.open_elements.pop
  else
    parse_error("unexpected-end-tag", {"name" => "head"})
  end
  @parser.phase = @parser.phases[:afterHead]
end

#endTagImplyAfterHead(name) ⇒ Object



101
102
103
104
# File 'lib/html5/html5parser/in_head_phase.rb', line 101

def endTagImplyAfterHead(name)
  anything_else
  @parser.phase.processEndTag(name)
end

#endTagOther(name) ⇒ Object



114
115
116
# File 'lib/html5/html5parser/in_head_phase.rb', line 114

def endTagOther(name)
  parse_error("unexpected-end-tag", {"name" => name})
end

#endTagTitleStyleScriptNoscript(name) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/html5/html5parser/in_head_phase.rb', line 106

def endTagTitleStyleScriptNoscript(name)
  if @tree.open_elements.last.name == name
    @tree.open_elements.pop
  else
    parse_error("unexpected-end-tag", {"name" => name})
  end
end

#process_eofObject



13
14
15
16
17
18
19
20
# File 'lib/html5/html5parser/in_head_phase.rb', line 13

def process_eof
  if ['title', 'style', 'script'].include?(name = @tree.open_elements.last.name)
    parse_error("expected-named-closing-tag-but-got-eof", {"name" => @tree.open_elements.last.name})
    @tree.open_elements.pop
  end
  anything_else
  @parser.phase.process_eof
end

#processCharacters(data) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/html5/html5parser/in_head_phase.rb', line 22

def processCharacters(data)
  if %w[title style script noscript].include?(@tree.open_elements.last.name)
    @tree.insertText(data)
  else
    anything_else
    @parser.phase.processCharacters(data)
  end
end

#startTagBaseLinkMeta(name, attributes) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/html5/html5parser/in_head_phase.rb', line 78

def startTagBaseLinkMeta(name, attributes)
  element = @tree.createElement(name, attributes)
  if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
    appendToHead(element)
  else
    @tree.open_elements.last.appendChild(element)
  end
end

#startTagHead(name, attributes) ⇒ Object



31
32
33
# File 'lib/html5/html5parser/in_head_phase.rb', line 31

def startTagHead(name, attributes)
  parse_error("two-heads-are-not-better-than-one")
end

#startTagNoscript(name, attributes) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/html5/html5parser/in_head_phase.rb', line 53

def startTagNoscript(name, attributes)
  # XXX Need to decide whether to implement the scripting disabled case.
  element = @tree.createElement(name, attributes)
  if @tree.head_pointer !=nil and @parser.phase == @parser.phases[:inHead]
    appendToHead(element)
  else
    @tree.open_elements.last.appendChild(element)
  end
  @tree.open_elements.push(element)
  @parser.tokenizer.content_model_flag = :CDATA
end

#startTagOther(name, attributes) ⇒ Object



87
88
89
90
# File 'lib/html5/html5parser/in_head_phase.rb', line 87

def startTagOther(name, attributes)
  anything_else
  @parser.phase.processStartTag(name, attributes)
end

#startTagScript(name, attributes) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/html5/html5parser/in_head_phase.rb', line 65

def startTagScript(name, attributes)
  #XXX Inner HTML case may be wrong
  element = @tree.createElement(name, attributes)
  element._flags.push("parser-inserted")
  if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
    appendToHead(element)
  else
    @tree.open_elements.last.appendChild(element)
  end
  @tree.open_elements.push(element)
  @parser.tokenizer.content_model_flag = :CDATA
end

#startTagStyle(name, attributes) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/html5/html5parser/in_head_phase.rb', line 42

def startTagStyle(name, attributes)
  element = @tree.createElement(name, attributes)
  if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
    appendToHead(element)
  else
    @tree.open_elements.last.appendChild(element)
  end
  @tree.open_elements.push(element)
  @parser.tokenizer.content_model_flag = :CDATA
end

#startTagTitle(name, attributes) ⇒ Object



35
36
37
38
39
40
# File 'lib/html5/html5parser/in_head_phase.rb', line 35

def startTagTitle(name, attributes)
  element = @tree.createElement(name, attributes)
  appendToHead(element)
  @tree.open_elements.push(element)
  @parser.tokenizer.content_model_flag = :RCDATA
end