From 83f61a27d6f1ef053c00b4cc2fd9668fdf354ad8 Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Fri, 11 Nov 2011 11:41:46 +1100 Subject: [PATCH] html: parse column groups Pass tests1.dat, test 108:
| | | | | | | | | | | | | | | |
R=nigeltao CC=golang-dev https://golang.org/cl/5369061 --- src/pkg/html/parse.go | 50 +++++++++++++++++++++++++++++++++++++- src/pkg/html/parse_test.go | 2 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index eb0d5c2d09..6aef7e12ed 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -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 ( diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go index 0e93a9de84..c69bfa42ad 100644 --- a/src/pkg/html/parse_test.go +++ b/src/pkg/html/parse_test.go @@ -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}, } -- 2.50.0