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 InRowPhase < Phase
|
|
|
|
|
|
|
|
# http://www.whatwg.org/specs/web-apps/current-work/#in-row
|
|
|
|
|
|
|
|
handle_start 'html', %w( td th ) => 'TableCell', %w( caption col colgroup tbody tfoot thead tr ) => 'TableOther'
|
|
|
|
|
|
|
|
handle_end 'tr', 'table', %w( tbody tfoot thead ) => 'TableRowGroup', %w( body caption col colgroup html td th ) => 'Ignore'
|
|
|
|
|
|
|
|
def processCharacters(data)
|
|
|
|
@parser.phases[:inTable].processCharacters(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagTableCell(name, attributes)
|
|
|
|
clearStackToTableRowContext
|
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[:inCell]
|
|
|
|
@tree.activeFormattingElements.push(Marker)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagTableOther(name, attributes)
|
|
|
|
ignoreEndTag = ignoreEndTagTr
|
|
|
|
endTagTr('tr')
|
2007-08-30 19:19:10 +02:00
|
|
|
# XXX how are we sure it's always ignored in the inner_html case?
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processStartTag(name, attributes) unless ignoreEndTag
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOther(name, attributes)
|
|
|
|
@parser.phases[:inTable].processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTr(name)
|
|
|
|
if ignoreEndTagTr
|
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
|
|
|
else
|
|
|
|
clearStackToTableRowContext
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase = @parser.phases[:inTableBody]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTable(name)
|
|
|
|
ignoreEndTag = ignoreEndTagTr
|
|
|
|
endTagTr('tr')
|
|
|
|
# Reprocess the current tag if the tr end tag was not ignored
|
2007-08-30 19:19:10 +02:00
|
|
|
# XXX how are we sure it's always ignored in the inner_html case?
|
2007-05-30 17:45:52 +02:00
|
|
|
@parser.phase.processEndTag(name) unless ignoreEndTag
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTableRowGroup(name)
|
|
|
|
if in_scope?(name, true)
|
|
|
|
endTagTr('tr')
|
|
|
|
@parser.phase.processEndTag(name)
|
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
# inner_html case
|
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-in-table-row",
|
|
|
|
{"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def endTagOther(name)
|
|
|
|
@parser.phases[:inTable].processEndTag(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# XXX unify this with other table helper methods
|
|
|
|
def clearStackToTableRowContext
|
2007-08-30 19:19:10 +02:00
|
|
|
until %w[tr html].include?(name = @tree.open_elements.last.name)
|
2007-10-28 00:34:29 +02:00
|
|
|
parse_error("unexpected-implied-end-tag-in-table-row", {"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
|
|
|
|
end
|
|
|
|
|
|
|
|
def ignoreEndTagTr
|
|
|
|
not in_scope?('tr', :tableVariant => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|