mirror of
https://github.com/golang/go
synced 2024-11-20 04:14:49 -07:00
exp/html: improve InHeadIM
Clean up the flow of control, and add a case for doctype tokens (to ignore them). R=nigeltao CC=golang-dev https://golang.org/cl/6069045
This commit is contained in:
parent
acb550504f
commit
fca32f02e9
@ -477,13 +477,7 @@ func beforeHeadIM(p *parser) bool {
|
||||
|
||||
// Section 12.2.5.4.4.
|
||||
func inHeadIM(p *parser) bool {
|
||||
var (
|
||||
pop bool
|
||||
implied bool
|
||||
)
|
||||
switch p.tok.Type {
|
||||
case ErrorToken:
|
||||
implied = true
|
||||
case TextToken:
|
||||
s := strings.TrimLeft(p.tok.Data, whitespace)
|
||||
if len(s) < len(p.tok.Data) {
|
||||
@ -494,7 +488,6 @@ func inHeadIM(p *parser) bool {
|
||||
}
|
||||
p.tok.Data = s
|
||||
}
|
||||
implied = true
|
||||
case StartTagToken:
|
||||
switch p.tok.Data {
|
||||
case "html":
|
||||
@ -503,6 +496,7 @@ func inHeadIM(p *parser) bool {
|
||||
p.addElement(p.tok.Data, p.tok.Attr)
|
||||
p.oe.pop()
|
||||
p.acknowledgeSelfClosingTag()
|
||||
return true
|
||||
case "script", "title", "noscript", "noframes", "style":
|
||||
p.addElement(p.tok.Data, p.tok.Attr)
|
||||
p.setOriginalIM()
|
||||
@ -511,15 +505,19 @@ func inHeadIM(p *parser) bool {
|
||||
case "head":
|
||||
// Ignore the token.
|
||||
return true
|
||||
default:
|
||||
implied = true
|
||||
}
|
||||
case EndTagToken:
|
||||
switch p.tok.Data {
|
||||
case "head":
|
||||
pop = true
|
||||
n := p.oe.pop()
|
||||
if n.Data != "head" {
|
||||
panic("html: bad parser state: <head> element not found, in the in-head insertion mode")
|
||||
}
|
||||
p.im = afterHeadIM
|
||||
return true
|
||||
case "body", "html", "br":
|
||||
implied = true
|
||||
p.parseImpliedToken(EndTagToken, "head", nil)
|
||||
return false
|
||||
default:
|
||||
// Ignore the token.
|
||||
return true
|
||||
@ -530,16 +528,13 @@ func inHeadIM(p *parser) bool {
|
||||
Data: p.tok.Data,
|
||||
})
|
||||
return true
|
||||
case DoctypeToken:
|
||||
// Ignore the token.
|
||||
return true
|
||||
}
|
||||
if pop || implied {
|
||||
n := p.oe.pop()
|
||||
if n.Data != "head" {
|
||||
panic("html: bad parser state: <head> element not found, in the in-head insertion mode")
|
||||
}
|
||||
p.im = afterHeadIM
|
||||
return !implied
|
||||
}
|
||||
return true
|
||||
|
||||
p.parseImpliedToken(EndTagToken, "head", nil)
|
||||
return false
|
||||
}
|
||||
|
||||
// Section 12.2.5.4.6.
|
||||
|
Loading…
Reference in New Issue
Block a user