mirror of
https://github.com/golang/go
synced 2024-11-20 03:54:40 -07:00
exp/html: adjust inTableBodyIM to match spec
Clean up flow of control. Handle </tbody>, </tfoot>, and </thead>. Pass 5 additional tests. R=nigeltao CC=golang-dev https://golang.org/cl/6117057
This commit is contained in:
parent
555ca36c1d
commit
a09e9811dc
@ -68,6 +68,7 @@ const (
|
||||
buttonScope
|
||||
tableScope
|
||||
tableRowScope
|
||||
tableBodyScope
|
||||
)
|
||||
|
||||
// popUntil pops the stack of open elements at the highest element whose tag
|
||||
@ -160,6 +161,11 @@ func (p *parser) clearStackToContext(s scope) {
|
||||
p.oe = p.oe[:i+1]
|
||||
return
|
||||
}
|
||||
case tableBodyScope:
|
||||
if tag == "html" || tag == "tbody" || tag == "tfoot" || tag == "thead" {
|
||||
p.oe = p.oe[:i+1]
|
||||
return
|
||||
}
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
@ -1290,6 +1296,16 @@ func inCaptionIM(p *parser) bool {
|
||||
// Section 12.2.5.4.12.
|
||||
func inColumnGroupIM(p *parser) bool {
|
||||
switch p.tok.Type {
|
||||
case TextToken:
|
||||
s := strings.TrimLeft(p.tok.Data, whitespace)
|
||||
if len(s) < len(p.tok.Data) {
|
||||
// Add the initial whitespace to the current node.
|
||||
p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])
|
||||
if s == "" {
|
||||
return true
|
||||
}
|
||||
p.tok.Data = s
|
||||
}
|
||||
case CommentToken:
|
||||
p.addChild(&Node{
|
||||
Type: CommentNode,
|
||||
@ -1332,40 +1348,34 @@ func inColumnGroupIM(p *parser) bool {
|
||||
|
||||
// Section 12.2.5.4.13.
|
||||
func inTableBodyIM(p *parser) bool {
|
||||
var (
|
||||
add bool
|
||||
data string
|
||||
attr []Attribute
|
||||
consumed bool
|
||||
)
|
||||
switch p.tok.Type {
|
||||
case ErrorToken:
|
||||
// TODO.
|
||||
case TextToken:
|
||||
// TODO.
|
||||
case StartTagToken:
|
||||
switch p.tok.Data {
|
||||
case "tr":
|
||||
add = true
|
||||
data = p.tok.Data
|
||||
attr = p.tok.Attr
|
||||
consumed = true
|
||||
p.clearStackToContext(tableBodyScope)
|
||||
p.addElement(p.tok.Data, p.tok.Attr)
|
||||
p.im = inRowIM
|
||||
return true
|
||||
case "td", "th":
|
||||
add = true
|
||||
data = "tr"
|
||||
consumed = false
|
||||
case "caption", "col", "colgroup", "tbody", "tfoot", "thead":
|
||||
if !p.popUntil(tableScope, "tbody", "thead", "tfoot") {
|
||||
// Ignore the token.
|
||||
return true
|
||||
}
|
||||
p.im = inTableIM
|
||||
p.parseImpliedToken(StartTagToken, "tr", nil)
|
||||
return false
|
||||
default:
|
||||
// TODO.
|
||||
case "caption", "col", "colgroup", "tbody", "tfoot", "thead":
|
||||
if p.popUntil(tableScope, "tbody", "thead", "tfoot") {
|
||||
p.im = inTableIM
|
||||
return false
|
||||
}
|
||||
// Ignore the token.
|
||||
return true
|
||||
}
|
||||
case EndTagToken:
|
||||
switch p.tok.Data {
|
||||
case "tbody", "tfoot", "thead":
|
||||
if p.elementInScope(tableScope, p.tok.Data) {
|
||||
p.clearStackToContext(tableBodyScope)
|
||||
p.oe.pop()
|
||||
p.im = inTableIM
|
||||
}
|
||||
return true
|
||||
case "table":
|
||||
if p.popUntil(tableScope, "tbody", "thead", "tfoot") {
|
||||
p.im = inTableIM
|
||||
@ -1384,12 +1394,7 @@ func inTableBodyIM(p *parser) bool {
|
||||
})
|
||||
return true
|
||||
}
|
||||
if add {
|
||||
// TODO: clear the stack back to a table body context.
|
||||
p.addElement(data, attr)
|
||||
p.im = inRowIM
|
||||
return consumed
|
||||
}
|
||||
|
||||
return inTableIM(p)
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,11 @@ PASS "<tbody><a>"
|
||||
PASS "<tfoot><a>"
|
||||
PASS "<thead><a>"
|
||||
PASS "</table><a>"
|
||||
FAIL "<a><tr>"
|
||||
FAIL "<a><td>"
|
||||
FAIL "<a><td>"
|
||||
FAIL "<a><td>"
|
||||
FAIL "<td><table><tbody><a><tr>"
|
||||
PASS "<a><tr>"
|
||||
PASS "<a><td>"
|
||||
PASS "<a><td>"
|
||||
PASS "<a><td>"
|
||||
PASS "<td><table><tbody><a><tr>"
|
||||
PASS "</tr><td>"
|
||||
PASS "<td><table><a><tr></tr><tr>"
|
||||
PASS "<caption><td>"
|
||||
|
Loading…
Reference in New Issue
Block a user