]> Cypherpunks repositories - gostls13.git/commitdiff
html: parse <caption> elements
authorAndrew Balholm <andybalholm@gmail.com>
Wed, 16 Nov 2011 01:18:11 +0000 (12:18 +1100)
committerNigel Tao <nigeltao@golang.org>
Wed, 16 Nov 2011 01:18:11 +0000 (12:18 +1100)
Pass tests2.dat, test 33:
<!DOCTYPE html><table><caption>test TEST</caption><td>test

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <table>
|       <caption>
|         "test TEST"
|       <tbody>
|         <tr>
|           <td>
|             "test"

R=nigeltao
CC=golang-dev
https://golang.org/cl/5371099

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

index 5b91204240ae13f39d0e013985d8287c267cfa88..2c15d2d31e90aebd48e5aee0fd8b68d60f2373b6 100644 (file)
@@ -298,7 +298,7 @@ func (p *parser) resetInsertionMode() {
                case "tbody", "thead", "tfoot":
                        p.im = inTableBodyIM
                case "caption":
-                       // TODO: p.im = inCaptionIM
+                       p.im = inCaptionIM
                case "colgroup":
                        p.im = inColumnGroupIM
                case "table":
@@ -887,6 +887,12 @@ func inTableIM(p *parser) bool {
                // TODO.
        case StartTagToken:
                switch p.tok.Data {
+               case "caption":
+                       p.clearStackToContext(tableScopeStopTags)
+                       p.afe = append(p.afe, &scopeMarker)
+                       p.addElement(p.tok.Data, p.tok.Attr)
+                       p.im = inCaptionIM
+                       return true
                case "tbody", "tfoot", "thead":
                        p.clearStackToContext(tableScopeStopTags)
                        p.addElement(p.tok.Data, p.tok.Attr)
@@ -960,6 +966,46 @@ func (p *parser) clearStackToContext(stopTags []string) {
        }
 }
 
+// Section 11.2.5.4.11.
+func inCaptionIM(p *parser) bool {
+       switch p.tok.Type {
+       case StartTagToken:
+               switch p.tok.Data {
+               case "caption", "col", "colgroup", "tbody", "td", "tfoot", "thead", "tr":
+                       if p.popUntil(tableScopeStopTags, "caption") {
+                               p.clearActiveFormattingElements()
+                               p.im = inTableIM
+                               return false
+                       } else {
+                               // Ignore the token.
+                               return true
+                       }
+               }
+       case EndTagToken:
+               switch p.tok.Data {
+               case "caption":
+                       if p.popUntil(tableScopeStopTags, "caption") {
+                               p.clearActiveFormattingElements()
+                               p.im = inTableIM
+                       }
+                       return true
+               case "table":
+                       if p.popUntil(tableScopeStopTags, "caption") {
+                               p.clearActiveFormattingElements()
+                               p.im = inTableIM
+                               return false
+                       } else {
+                               // Ignore the token.
+                               return true
+                       }
+               case "body", "col", "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr":
+                       // Ignore the token.
+                       return true
+               }
+       }
+       return inBodyIM(p)
+}
+
 // Section 11.2.5.4.12.
 func inColumnGroupIM(p *parser) bool {
        switch p.tok.Type {
index 0fd2dc82b301ef14a0bb6c6c326dbef81c46a86f..3837f34b1916323f457d9f0731a0f28ec008024c 100644 (file)
@@ -134,7 +134,7 @@ func TestParser(t *testing.T) {
        }{
                // TODO(nigeltao): Process all the test cases from all the .dat files.
                {"tests1.dat", -1},
-               {"tests2.dat", 33},
+               {"tests2.dat", 34},
                {"tests3.dat", 0},
        }
        for _, tf := range testFiles {