1
0
mirror of https://github.com/golang/go synced 2024-11-20 03:34:40 -07:00

html: parse column groups

Pass tests1.dat, test 108:
<table><colgroup><col><colgroup><col><col><col><colgroup><col><col><thead><tr><td></table>

| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <col>
|       <colgroup>
|         <col>
|         <col>
|         <col>
|       <colgroup>
|         <col>
|         <col>
|       <thead>
|         <tr>
|           <td>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5369061
This commit is contained in:
Andrew Balholm 2011-11-11 11:41:46 +11:00 committed by Nigel Tao
parent dd2abe5152
commit 83f61a27d6
2 changed files with 50 additions and 2 deletions

View File

@ -313,7 +313,7 @@ func (p *parser) resetInsertionMode() insertionMode {
case "caption":
// TODO: return inCaptionIM
case "colgroup":
// TODO: return inColumnGroupIM
return inColumnGroupIM
case "table":
return inTableIM
case "head":
@ -879,6 +879,14 @@ func inTableIM(p *parser) (insertionMode, bool) {
}
// Ignore the token.
return inTableIM, true
case "colgroup":
p.clearStackToContext(tableScopeStopTags)
p.addElement(p.tok.Data, p.tok.Attr)
return inColumnGroupIM, true
case "col":
p.clearStackToContext(tableScopeStopTags)
p.addElement("colgroup", p.tok.Attr)
return inColumnGroupIM, false
default:
// TODO.
}
@ -924,6 +932,46 @@ func (p *parser) clearStackToContext(stopTags []string) {
}
}
// Section 11.2.5.4.12.
func inColumnGroupIM(p *parser) (insertionMode, bool) {
switch p.tok.Type {
case CommentToken:
p.addChild(&Node{
Type: CommentNode,
Data: p.tok.Data,
})
return inColumnGroupIM, true
case DoctypeToken:
// Ignore the token.
return inColumnGroupIM, true
case StartTagToken:
switch p.tok.Data {
case "html":
return useTheRulesFor(p, inColumnGroupIM, inBodyIM)
case "col":
p.addElement(p.tok.Data, p.tok.Attr)
p.oe.pop()
p.acknowledgeSelfClosingTag()
return inColumnGroupIM, true
}
case EndTagToken:
switch p.tok.Data {
case "colgroup":
if p.oe.top().Data != "html" {
p.oe.pop()
}
return inTableIM, true
case "col":
// Ignore the token.
return inColumnGroupIM, true
}
}
if p.oe.top().Data != "html" {
p.oe.pop()
}
return inTableIM, false
}
// Section 11.2.5.4.13.
func inTableBodyIM(p *parser) (insertionMode, bool) {
var (

View File

@ -133,7 +133,7 @@ func TestParser(t *testing.T) {
n int
}{
// TODO(nigeltao): Process all the test cases from all the .dat files.
{"tests1.dat", 108},
{"tests1.dat", 109},
{"tests2.dat", 0},
{"tests3.dat", 0},
}