mirror of
https://github.com/golang/go
synced 2024-11-20 06:44:40 -07:00
exp/html: improve beforeHeadIM
Add a case to ignore doctype tokens. Clean up the flow of control to more clearly match the spec. Pass one more test. R=nigeltao CC=golang-dev https://golang.org/cl/6062047
This commit is contained in:
parent
b39bbf1e5b
commit
b65c9a633e
@ -446,37 +446,30 @@ func beforeHTMLIM(p *parser) bool {
|
|||||||
|
|
||||||
// Section 12.2.5.4.3.
|
// Section 12.2.5.4.3.
|
||||||
func beforeHeadIM(p *parser) bool {
|
func beforeHeadIM(p *parser) bool {
|
||||||
var (
|
|
||||||
add bool
|
|
||||||
attr []Attribute
|
|
||||||
implied bool
|
|
||||||
)
|
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
|
||||||
implied = true
|
|
||||||
case TextToken:
|
case TextToken:
|
||||||
p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace)
|
p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace)
|
||||||
if len(p.tok.Data) == 0 {
|
if len(p.tok.Data) == 0 {
|
||||||
// It was all whitespace, so ignore it.
|
// It was all whitespace, so ignore it.
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
implied = true
|
|
||||||
case StartTagToken:
|
case StartTagToken:
|
||||||
switch p.tok.Data {
|
switch p.tok.Data {
|
||||||
case "head":
|
case "head":
|
||||||
add = true
|
p.addElement(p.tok.Data, p.tok.Attr)
|
||||||
attr = p.tok.Attr
|
p.head = p.top()
|
||||||
|
p.im = inHeadIM
|
||||||
|
return true
|
||||||
case "html":
|
case "html":
|
||||||
return inBodyIM(p)
|
return inBodyIM(p)
|
||||||
default:
|
|
||||||
implied = true
|
|
||||||
}
|
}
|
||||||
case EndTagToken:
|
case EndTagToken:
|
||||||
switch p.tok.Data {
|
switch p.tok.Data {
|
||||||
case "head", "body", "html", "br":
|
case "head", "body", "html", "br":
|
||||||
implied = true
|
// Drop down to adding an implied <head> tag.
|
||||||
default:
|
default:
|
||||||
// Ignore the token.
|
// Ignore the token.
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
case CommentToken:
|
case CommentToken:
|
||||||
p.addChild(&Node{
|
p.addChild(&Node{
|
||||||
@ -484,13 +477,15 @@ func beforeHeadIM(p *parser) bool {
|
|||||||
Data: p.tok.Data,
|
Data: p.tok.Data,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
case DoctypeToken:
|
||||||
|
// Ignore the token.
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if add || implied {
|
|
||||||
p.addElement("head", attr)
|
p.addElement("head", nil)
|
||||||
p.head = p.top()
|
p.head = p.top()
|
||||||
}
|
|
||||||
p.im = inHeadIM
|
p.im = inHeadIM
|
||||||
return !implied
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 12.2.5.4.4.
|
// Section 12.2.5.4.4.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
FAIL "<!doctype html><math><mn DefinitionUrl=\"foo\">"
|
FAIL "<!doctype html><math><mn DefinitionUrl=\"foo\">"
|
||||||
FAIL "<!doctype html><html></p><!--foo-->"
|
PASS "<!doctype html><html></p><!--foo-->"
|
||||||
PASS "<!doctype html><head></head></p><!--foo-->"
|
PASS "<!doctype html><head></head></p><!--foo-->"
|
||||||
FAIL "<!doctype html><body><p><pre>"
|
FAIL "<!doctype html><body><p><pre>"
|
||||||
FAIL "<!doctype html><body><p><listing>"
|
FAIL "<!doctype html><body><p><listing>"
|
||||||
|
Loading…
Reference in New Issue
Block a user