diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index ba7e705a794..5b25e2620d0 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -234,6 +234,41 @@ func (p *parser) setOriginalIM(im insertionMode) { p.originalIM = im } +// Section 11.2.3.1, "reset the insertion mode". +func (p *parser) resetInsertionMode() insertionMode { + for i := len(p.oe) - 1; i >= 0; i-- { + n := p.oe[i] + if i == 0 { + // TODO: set n to the context element, for HTML fragment parsing. + } + switch n.Data { + case "select": + return inSelectIM + case "td", "th": + return inCellIM + case "tr": + return inRowIM + case "tbody", "thead", "tfoot": + return inTableBodyIM + case "caption": + // TODO: return inCaptionIM + case "colgroup": + // TODO: return inColumnGroupIM + case "table": + return inTableIM + case "head": + return inBodyIM + case "body": + return inBodyIM + case "frameset": + // TODO: return inFramesetIM + case "html": + return beforeHeadIM + } + } + return inBodyIM +} + // Section 11.2.5.4.1. func initialIM(p *parser) (insertionMode, bool) { switch p.tok.Type { @@ -478,6 +513,12 @@ func inBodyIM(p *parser) (insertionMode, bool) { p.oe.pop() p.acknowledgeSelfClosingTag() p.framesetOK = false + case "select": + p.reconstructActiveFormattingElements() + p.addElement(p.tok.Data, p.tok.Attr) + p.framesetOK = false + // TODO: detect