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 InCaptionPhase < Phase
|
|
|
|
|
|
|
|
# http://www.whatwg.org/specs/web-apps/current-work/#in-caption
|
|
|
|
|
2007-10-28 00:34:29 +02:00
|
|
|
handle_start 'html', %w(caption col colgroup tbody td tfoot th thead tr) => 'TableElement'
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-10-28 00:34:29 +02:00
|
|
|
handle_end 'caption', 'table', %w(body col colgroup html tbody td tfoot th thead tr) => 'Ignore'
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
def ignoreEndTagCaption
|
2007-08-30 19:19:10 +02:00
|
|
|
!in_scope?('caption', true)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def processCharacters(data)
|
|
|
|
@parser.phases[:inBody].processCharacters(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagTableElement(name, attributes)
|
2007-10-28 00:34:29 +02:00
|
|
|
parse_error "unexpected-end-tag", {"name" => name}
|
2007-05-30 17:45:52 +02:00
|
|
|
#XXX Have to duplicate logic here to find out if the tag is ignored
|
|
|
|
ignoreEndTag = ignoreEndTagCaption
|
|
|
|
@parser.phase.processEndTag('caption')
|
|
|
|
@parser.phase.processStartTag(name, attributes) unless ignoreEndTag
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOther(name, attributes)
|
|
|
|
@parser.phases[:inBody].processStartTag(name, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagCaption(name)
|
|
|
|
if ignoreEndTagCaption
|
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
|
|
|
|
# AT this code is quite similar to endTagTable in "InTable"
|
|
|
|
@tree.generateImpliedEndTags
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
unless @tree.open_elements[-1].name == 'caption'
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("expected-one-end-tag-but-got-another",
|
|
|
|
{"gotName" => "caption",
|
2007-10-28 00:34:29 +02:00
|
|
|
"expectedName" => @tree.open_elements.last.name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
remove_open_elements_until('caption')
|
|
|
|
|
|
|
|
@tree.clearActiveFormattingElements
|
|
|
|
@parser.phase = @parser.phases[:inTable]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTable(name)
|
2007-10-28 00:34:29 +02:00
|
|
|
parse_error "unexpected-end-table-in-caption"
|
2007-05-30 17:45:52 +02:00
|
|
|
ignoreEndTag = ignoreEndTagCaption
|
|
|
|
@parser.phase.processEndTag('caption')
|
|
|
|
@parser.phase.processEndTag(name) unless ignoreEndTag
|
|
|
|
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)
|
|
|
|
@parser.phases[:inBody].processEndTag(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|