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 RootElementPhase < Phase
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
def process_eof
|
|
|
|
insert_html_element
|
|
|
|
@parser.phase.process_eof
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def processComment(data)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_comment(data, @tree.document)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def processSpaceCharacters(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def processCharacters(data)
|
2007-08-30 19:19:10 +02:00
|
|
|
insert_html_element
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processCharacters(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def processStartTag(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
@parser.first_start_tag = true if name == 'html'
|
|
|
|
insert_html_element
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def processEndTag(name)
|
2007-08-30 19:19:10 +02:00
|
|
|
insert_html_element
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processEndTag(name)
|
|
|
|
end
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
def insert_html_element
|
2007-05-30 17:45:52 +02:00
|
|
|
element = @tree.createElement('html', {})
|
2007-10-06 18:55:58 +02:00
|
|
|
@tree.open_elements << element
|
2007-05-30 17:45:52 +02:00
|
|
|
@tree.document.appendChild(element)
|
|
|
|
@parser.phase = @parser.phases[:beforeHead]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|