]> Cypherpunks repositories - gostls13.git/commitdiff
html: parse column groups
authorAndrew Balholm <andybalholm@gmail.com>
Fri, 11 Nov 2011 00:41:46 +0000 (11:41 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 11 Nov 2011 00:41:46 +0000 (11:41 +1100)
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

src/pkg/html/parse.go
src/pkg/html/parse_test.go

index eb0d5c2d098a0244bc5ce61361bf15f06631a19a..6aef7e12edf608693bff4288fc5db28ef30abf9e 100644 (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 (
index 0e93a9de84492104f8486cc67d29c02288999529..c69bfa42adf869d7fd9d57e243b7ae865462fed3 100644 (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},
        }