Commit a09e9811 authored by Andrew Balholm's avatar Andrew Balholm Committed by Nigel Tao

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
parent 555ca36c
...@@ -68,6 +68,7 @@ const ( ...@@ -68,6 +68,7 @@ const (
buttonScope buttonScope
tableScope tableScope
tableRowScope tableRowScope
tableBodyScope
) )
// popUntil pops the stack of open elements at the highest element whose tag // popUntil pops the stack of open elements at the highest element whose tag
...@@ -160,6 +161,11 @@ func (p *parser) clearStackToContext(s scope) { ...@@ -160,6 +161,11 @@ func (p *parser) clearStackToContext(s scope) {
p.oe = p.oe[:i+1] p.oe = p.oe[:i+1]
return return
} }
case tableBodyScope:
if tag == "html" || tag == "tbody" || tag == "tfoot" || tag == "thead" {
p.oe = p.oe[:i+1]
return
}
default: default:
panic("unreachable") panic("unreachable")
} }
...@@ -1290,6 +1296,16 @@ func inCaptionIM(p *parser) bool { ...@@ -1290,6 +1296,16 @@ func inCaptionIM(p *parser) bool {
// Section 12.2.5.4.12. // Section 12.2.5.4.12.
func inColumnGroupIM(p *parser) bool { func inColumnGroupIM(p *parser) bool {
switch p.tok.Type { 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: case CommentToken:
p.addChild(&Node{ p.addChild(&Node{
Type: CommentNode, Type: CommentNode,
...@@ -1332,40 +1348,34 @@ func inColumnGroupIM(p *parser) bool { ...@@ -1332,40 +1348,34 @@ func inColumnGroupIM(p *parser) bool {
// Section 12.2.5.4.13. // Section 12.2.5.4.13.
func inTableBodyIM(p *parser) bool { func inTableBodyIM(p *parser) bool {
var (
add bool
data string
attr []Attribute
consumed bool
)
switch p.tok.Type { switch p.tok.Type {
case ErrorToken:
// TODO.
case TextToken:
// TODO.
case StartTagToken: case StartTagToken:
switch p.tok.Data { switch p.tok.Data {
case "tr": case "tr":
add = true p.clearStackToContext(tableBodyScope)
data = p.tok.Data p.addElement(p.tok.Data, p.tok.Attr)
attr = p.tok.Attr p.im = inRowIM
consumed = true return true
case "td", "th": case "td", "th":
add = true p.parseImpliedToken(StartTagToken, "tr", nil)
data = "tr" return false
consumed = false
case "caption", "col", "colgroup", "tbody", "tfoot", "thead": case "caption", "col", "colgroup", "tbody", "tfoot", "thead":
if !p.popUntil(tableScope, "tbody", "thead", "tfoot") { if p.popUntil(tableScope, "tbody", "thead", "tfoot") {
// Ignore the token.
return true
}
p.im = inTableIM p.im = inTableIM
return false return false
default: }
// TODO. // Ignore the token.
return true
} }
case EndTagToken: case EndTagToken:
switch p.tok.Data { 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": case "table":
if p.popUntil(tableScope, "tbody", "thead", "tfoot") { if p.popUntil(tableScope, "tbody", "thead", "tfoot") {
p.im = inTableIM p.im = inTableIM
...@@ -1384,12 +1394,7 @@ func inTableBodyIM(p *parser) bool { ...@@ -1384,12 +1394,7 @@ func inTableBodyIM(p *parser) bool {
}) })
return true 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) return inTableIM(p)
} }
......
...@@ -43,11 +43,11 @@ PASS "<tbody><a>" ...@@ -43,11 +43,11 @@ PASS "<tbody><a>"
PASS "<tfoot><a>" PASS "<tfoot><a>"
PASS "<thead><a>" PASS "<thead><a>"
PASS "</table><a>" PASS "</table><a>"
FAIL "<a><tr>" PASS "<a><tr>"
FAIL "<a><td>" PASS "<a><td>"
FAIL "<a><td>" PASS "<a><td>"
FAIL "<a><td>" PASS "<a><td>"
FAIL "<td><table><tbody><a><tr>" PASS "<td><table><tbody><a><tr>"
PASS "</tr><td>" PASS "</tr><td>"
PASS "<td><table><a><tr></tr><tr>" PASS "<td><table><a><tr></tr><tr>"
PASS "<caption><td>" PASS "<caption><td>"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment