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 InTablePhase < Phase
|
|
|
|
|
|
|
|
# http://www.whatwg.org/specs/web-apps/current-work/#in-table
|
|
|
|
|
|
|
|
handle_start 'html', 'caption', 'colgroup', 'col', 'table'
|
|
|
|
|
|
|
|
handle_start %w( tbody tfoot thead ) => 'RowGroup', %w( td th tr ) => 'ImplyTbody'
|
|
|
|
|
|
|
|
handle_end 'table', %w( body caption col colgroup html tbody td tfoot th thead tr ) => 'Ignore'
|
|
|
|
|
|
|
|
def processCharacters(data)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-char-implies-table-voodoo")
|
2007-05-30 17:45:52 +02:00
|
|
|
# Make all the special element rearranging voodoo kick in
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = true
|
2007-05-30 17:45:52 +02:00
|
|
|
# Process the character in the "in body" mode
|
|
|
|
@parser.phases[:inBody].processCharacters(data)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = false
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagCaption(name, attributes)
|
|
|
|
clearStackToTableContext
|
|
|
|
@tree.activeFormattingElements.push(Marker)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_element(name, attributes)
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase = @parser.phases[:inCaption]
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagColgroup(name, attributes)
|
|
|
|
clearStackToTableContext
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_element(name, attributes)
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase = @parser.phases[:inColumnGroup]
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagCol(name, attributes)
|
|
|
|
startTagColgroup('colgroup', {})
|
|
|
|
@parser.phase.processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagRowGroup(name, attributes)
|
|
|
|
clearStackToTableContext
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_element(name, attributes)
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase = @parser.phases[:inTableBody]
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagImplyTbody(name, attributes)
|
|
|
|
startTagRowGroup('tbody', {})
|
|
|
|
@parser.phase.processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagTable(name, attributes)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-start-tag-implies-end-tag",
|
|
|
|
{"startName" => "table", "endName" => "table"})
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processEndTag('table')
|
2007-08-30 19:19:10 +02:00
|
|
|
@parser.phase.processStartTag(name, attributes) unless @parser.inner_html
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOther(name, attributes)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-start-tag-implies-table-voodoo",
|
|
|
|
{"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
# Make all the special element rearranging voodoo kick in
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = true
|
2007-05-30 17:45:52 +02:00
|
|
|
# Process the start tag in the "in body" mode
|
|
|
|
@parser.phases[:inBody].processStartTag(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = false
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTable(name)
|
|
|
|
if in_scope?('table', true)
|
|
|
|
@tree.generateImpliedEndTags
|
2007-08-30 19:19:10 +02:00
|
|
|
|
|
|
|
unless @tree.open_elements.last.name == 'table'
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("end-tag-too-early-named",
|
|
|
|
{"gotName" => "table",
|
|
|
|
"expectedName" => @tree.open_elements.last.name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
2007-08-30 19:19:10 +02:00
|
|
|
|
2007-05-30 17:45:52 +02:00
|
|
|
remove_open_elements_until('table')
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
@parser.reset_insertion_mode
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
# inner_html case
|
|
|
|
assert @parser.inner_html
|
2007-10-28 00:34:29 +02:00
|
|
|
parse_error "unexpected-end-tag", {:name => name}
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagIgnore(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
|
|
|
|
|
|
|
|
def endTagOther(name)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag-implies-table-voodoo", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
# Make all the special element rearranging voodoo kick in
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = true
|
2007-05-30 17:45:52 +02:00
|
|
|
# Process the end tag in the "in body" mode
|
|
|
|
@parser.phases[:inBody].processEndTag(name)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.insert_from_table = false
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def clearStackToTableContext
|
|
|
|
# "clear the stack back to a table context"
|
2007-08-30 19:19:10 +02:00
|
|
|
until %w[table html].include?(name = @tree.open_elements.last.name)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-implied-end-tag-in-table",
|
|
|
|
{"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
|
|
|
# When the current node is <html> it's an inner_html case
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2007-06-05 23:34:49 +02:00
|
|
|
end
|