2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/html5parser/phase'
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
module HTML5
|
2007-05-30 17:45:52 +02:00
|
|
|
class InHeadPhase < Phase
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
handle_start 'html', 'head', 'title', 'style', 'script', 'noscript'
|
|
|
|
handle_start %w( base link meta )
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-06-22 10:12:08 +02:00
|
|
|
handle_end 'head'
|
2007-07-05 00:36:59 +02:00
|
|
|
handle_end %w( html body br p ) => 'ImplyAfterHead'
|
2007-08-30 19:19:10 +02:00
|
|
|
handle_end %w( title style script noscript )
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
def process_eof
|
|
|
|
if ['title', 'style', 'script'].include?(name = @tree.open_elements.last.name)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("expected-named-closing-tag-but-got-eof", {"name" => @tree.open_elements.last.name})
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-08-30 19:19:10 +02:00
|
|
|
anything_else
|
|
|
|
@parser.phase.process_eof
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def processCharacters(data)
|
2007-08-30 19:19:10 +02:00
|
|
|
if %w[title style script noscript].include?(@tree.open_elements.last.name)
|
2007-05-30 17:45:52 +02:00
|
|
|
@tree.insertText(data)
|
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
anything_else
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processCharacters(data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagHead(name, attributes)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("two-heads-are-not-better-than-one")
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagTitle(name, attributes)
|
|
|
|
element = @tree.createElement(name, attributes)
|
|
|
|
appendToHead(element)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.push(element)
|
|
|
|
@parser.tokenizer.content_model_flag = :RCDATA
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagStyle(name, attributes)
|
|
|
|
element = @tree.createElement(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
|
2007-05-30 17:45:52 +02:00
|
|
|
appendToHead(element)
|
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.last.appendChild(element)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.push(element)
|
|
|
|
@parser.tokenizer.content_model_flag = :CDATA
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagScript(name, attributes)
|
|
|
|
#XXX Inner HTML case may be wrong
|
|
|
|
element = @tree.createElement(name, attributes)
|
|
|
|
element._flags.push("parser-inserted")
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
|
2007-05-30 17:45:52 +02:00
|
|
|
appendToHead(element)
|
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.last.appendChild(element)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.push(element)
|
|
|
|
@parser.tokenizer.content_model_flag = :CDATA
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagBaseLinkMeta(name, attributes)
|
|
|
|
element = @tree.createElement(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.head_pointer != nil and @parser.phase == @parser.phases[:inHead]
|
2007-06-22 10:12:08 +02:00
|
|
|
appendToHead(element)
|
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.last.appendChild(element)
|
2007-06-22 10:12:08 +02:00
|
|
|
end
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOther(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
anything_else
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagHead(name)
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.open_elements.last.name == 'head'
|
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag", {"name" => "head"})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
@parser.phase = @parser.phases[:afterHead]
|
|
|
|
end
|
|
|
|
|
2007-06-22 10:12:08 +02:00
|
|
|
def endTagImplyAfterHead(name)
|
2007-08-30 19:19:10 +02:00
|
|
|
anything_else
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processEndTag(name)
|
|
|
|
end
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
def endTagTitleStyleScriptNoscript(name)
|
|
|
|
if @tree.open_elements.last.name == name
|
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagOther(name)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
def anything_else
|
|
|
|
if @tree.open_elements.last.name == 'head'
|
2007-05-30 17:45:52 +02:00
|
|
|
endTagHead('head')
|
|
|
|
else
|
|
|
|
@parser.phase = @parser.phases[:afterHead]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def appendToHead(element)
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.head_pointer.nil?
|
|
|
|
assert @parser.inner_html
|
|
|
|
@tree.open_elements.last.appendChild(element)
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.head_pointer.appendChild(element)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2007-06-22 10:12:08 +02:00
|
|
|
end
|