mirror of
https://github.com/golang/go
synced 2024-11-25 14:27:57 -07:00
html: update comments to match latest spec.
R=dsymonds CC=golang-dev https://golang.org/cl/5482054
This commit is contained in:
parent
b9064fb132
commit
66113ac818
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
package html
|
package html
|
||||||
|
|
||||||
// Section 11.2.3.2 of the HTML5 specification says "The following elements
|
// Section 12.2.3.2 of the HTML5 specification says "The following elements
|
||||||
// have varying levels of special parsing rules".
|
// have varying levels of special parsing rules".
|
||||||
// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements
|
||||||
var isSpecialElement = map[string]bool{
|
var isSpecialElement = map[string]bool{
|
||||||
|
@ -17,7 +17,7 @@ const (
|
|||||||
scopeMarkerNode
|
scopeMarkerNode
|
||||||
)
|
)
|
||||||
|
|
||||||
// Section 11.2.3.3 says "scope markers are inserted when entering applet
|
// Section 12.2.3.3 says "scope markers are inserted when entering applet
|
||||||
// elements, buttons, object elements, marquees, table cells, and table
|
// elements, buttons, object elements, marquees, table cells, and table
|
||||||
// captions, and are used to prevent formatting from 'leaking'".
|
// captions, and are used to prevent formatting from 'leaking'".
|
||||||
var scopeMarker = Node{Type: scopeMarkerNode}
|
var scopeMarker = Node{Type: scopeMarkerNode}
|
||||||
|
@ -22,12 +22,12 @@ type parser struct {
|
|||||||
hasSelfClosingToken bool
|
hasSelfClosingToken bool
|
||||||
// doc is the document root element.
|
// doc is the document root element.
|
||||||
doc *Node
|
doc *Node
|
||||||
// The stack of open elements (section 11.2.3.2) and active formatting
|
// The stack of open elements (section 12.2.3.2) and active formatting
|
||||||
// elements (section 11.2.3.3).
|
// elements (section 12.2.3.3).
|
||||||
oe, afe nodeStack
|
oe, afe nodeStack
|
||||||
// Element pointers (section 11.2.3.4).
|
// Element pointers (section 12.2.3.4).
|
||||||
head, form *Node
|
head, form *Node
|
||||||
// Other parsing state flags (section 11.2.3.5).
|
// Other parsing state flags (section 12.2.3.5).
|
||||||
scripting, framesetOK bool
|
scripting, framesetOK bool
|
||||||
// im is the current insertion mode.
|
// im is the current insertion mode.
|
||||||
im insertionMode
|
im insertionMode
|
||||||
@ -35,12 +35,12 @@ type parser struct {
|
|||||||
// or inTableText insertion mode.
|
// or inTableText insertion mode.
|
||||||
originalIM insertionMode
|
originalIM insertionMode
|
||||||
// fosterParenting is whether new elements should be inserted according to
|
// fosterParenting is whether new elements should be inserted according to
|
||||||
// the foster parenting rules (section 11.2.5.3).
|
// the foster parenting rules (section 12.2.5.3).
|
||||||
fosterParenting bool
|
fosterParenting bool
|
||||||
// quirks is whether the parser is operating in "quirks mode."
|
// quirks is whether the parser is operating in "quirks mode."
|
||||||
quirks bool
|
quirks bool
|
||||||
// context is the context element when parsing an HTML fragment
|
// context is the context element when parsing an HTML fragment
|
||||||
// (section 11.4).
|
// (section 12.4).
|
||||||
context *Node
|
context *Node
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func (p *parser) top() *Node {
|
|||||||
return p.doc
|
return p.doc
|
||||||
}
|
}
|
||||||
|
|
||||||
// stopTags for use in popUntil. These come from section 11.2.3.2.
|
// stopTags for use in popUntil. These come from section 12.2.3.2.
|
||||||
var (
|
var (
|
||||||
defaultScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object"}
|
defaultScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object"}
|
||||||
listItemScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object", "ol", "ul"}
|
listItemScopeStopTags = []string{"applet", "caption", "html", "table", "td", "th", "marquee", "object", "ol", "ul"}
|
||||||
@ -130,7 +130,7 @@ func (p *parser) addChild(n *Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fosterParent adds a child node according to the foster parenting rules.
|
// fosterParent adds a child node according to the foster parenting rules.
|
||||||
// Section 11.2.5.3, "foster parenting".
|
// Section 12.2.5.3, "foster parenting".
|
||||||
func (p *parser) fosterParent(n *Node) {
|
func (p *parser) fosterParent(n *Node) {
|
||||||
p.fosterParenting = false
|
p.fosterParenting = false
|
||||||
var table, parent *Node
|
var table, parent *Node
|
||||||
@ -199,14 +199,14 @@ func (p *parser) addElement(tag string, attr []Attribute) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.3.3.
|
// Section 12.2.3.3.
|
||||||
func (p *parser) addFormattingElement(tag string, attr []Attribute) {
|
func (p *parser) addFormattingElement(tag string, attr []Attribute) {
|
||||||
p.addElement(tag, attr)
|
p.addElement(tag, attr)
|
||||||
p.afe = append(p.afe, p.top())
|
p.afe = append(p.afe, p.top())
|
||||||
// TODO.
|
// TODO.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.3.3.
|
// Section 12.2.3.3.
|
||||||
func (p *parser) clearActiveFormattingElements() {
|
func (p *parser) clearActiveFormattingElements() {
|
||||||
for {
|
for {
|
||||||
n := p.afe.pop()
|
n := p.afe.pop()
|
||||||
@ -216,7 +216,7 @@ func (p *parser) clearActiveFormattingElements() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.3.3.
|
// Section 12.2.3.3.
|
||||||
func (p *parser) reconstructActiveFormattingElements() {
|
func (p *parser) reconstructActiveFormattingElements() {
|
||||||
n := p.afe.top()
|
n := p.afe.top()
|
||||||
if n == nil {
|
if n == nil {
|
||||||
@ -266,12 +266,12 @@ func (p *parser) read() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.4.
|
// Section 12.2.4.
|
||||||
func (p *parser) acknowledgeSelfClosingTag() {
|
func (p *parser) acknowledgeSelfClosingTag() {
|
||||||
p.hasSelfClosingToken = false
|
p.hasSelfClosingToken = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// An insertion mode (section 11.2.3.1) is the state transition function from
|
// An insertion mode (section 12.2.3.1) is the state transition function from
|
||||||
// a particular state in the HTML5 parser's state machine. It updates the
|
// a particular state in the HTML5 parser's state machine. It updates the
|
||||||
// parser's fields depending on parser.tok (where ErrorToken means EOF).
|
// parser's fields depending on parser.tok (where ErrorToken means EOF).
|
||||||
// It returns whether the token was consumed.
|
// It returns whether the token was consumed.
|
||||||
@ -279,7 +279,7 @@ type insertionMode func(*parser) bool
|
|||||||
|
|
||||||
// setOriginalIM sets the insertion mode to return to after completing a text or
|
// setOriginalIM sets the insertion mode to return to after completing a text or
|
||||||
// inTableText insertion mode.
|
// inTableText insertion mode.
|
||||||
// Section 11.2.3.1, "using the rules for".
|
// Section 12.2.3.1, "using the rules for".
|
||||||
func (p *parser) setOriginalIM() {
|
func (p *parser) setOriginalIM() {
|
||||||
if p.originalIM != nil {
|
if p.originalIM != nil {
|
||||||
panic("html: bad parser state: originalIM was set twice")
|
panic("html: bad parser state: originalIM was set twice")
|
||||||
@ -287,7 +287,7 @@ func (p *parser) setOriginalIM() {
|
|||||||
p.originalIM = p.im
|
p.originalIM = p.im
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.3.1, "reset the insertion mode".
|
// Section 12.2.3.1, "reset the insertion mode".
|
||||||
func (p *parser) resetInsertionMode() {
|
func (p *parser) resetInsertionMode() {
|
||||||
for i := len(p.oe) - 1; i >= 0; i-- {
|
for i := len(p.oe) - 1; i >= 0; i-- {
|
||||||
n := p.oe[i]
|
n := p.oe[i]
|
||||||
@ -331,7 +331,7 @@ func (p *parser) resetInsertionMode() {
|
|||||||
|
|
||||||
const whitespace = " \t\r\n\f"
|
const whitespace = " \t\r\n\f"
|
||||||
|
|
||||||
// Section 11.2.5.4.1.
|
// Section 12.2.5.4.1.
|
||||||
func initialIM(p *parser) bool {
|
func initialIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case TextToken:
|
case TextToken:
|
||||||
@ -358,7 +358,7 @@ func initialIM(p *parser) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.2.
|
// Section 12.2.5.4.2.
|
||||||
func beforeHTMLIM(p *parser) bool {
|
func beforeHTMLIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case TextToken:
|
case TextToken:
|
||||||
@ -394,7 +394,7 @@ func beforeHTMLIM(p *parser) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.3.
|
// Section 12.2.5.4.3.
|
||||||
func beforeHeadIM(p *parser) bool {
|
func beforeHeadIM(p *parser) bool {
|
||||||
var (
|
var (
|
||||||
add bool
|
add bool
|
||||||
@ -443,7 +443,7 @@ func beforeHeadIM(p *parser) bool {
|
|||||||
return !implied
|
return !implied
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.4.
|
// Section 12.2.5.4.4.
|
||||||
func inHeadIM(p *parser) bool {
|
func inHeadIM(p *parser) bool {
|
||||||
var (
|
var (
|
||||||
pop bool
|
pop bool
|
||||||
@ -510,7 +510,7 @@ func inHeadIM(p *parser) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.6.
|
// Section 12.2.5.4.6.
|
||||||
func afterHeadIM(p *parser) bool {
|
func afterHeadIM(p *parser) bool {
|
||||||
var (
|
var (
|
||||||
add bool
|
add bool
|
||||||
@ -598,7 +598,7 @@ func copyAttributes(dst *Node, src Token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.7.
|
// Section 12.2.5.4.7.
|
||||||
func inBodyIM(p *parser) bool {
|
func inBodyIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case TextToken:
|
case TextToken:
|
||||||
@ -989,7 +989,7 @@ func (p *parser) inBodyEndTagOther(tag string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.8.
|
// Section 12.2.5.4.8.
|
||||||
func textIM(p *parser) bool {
|
func textIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
case ErrorToken:
|
||||||
@ -1005,7 +1005,7 @@ func textIM(p *parser) bool {
|
|||||||
return p.tok.Type == EndTagToken
|
return p.tok.Type == EndTagToken
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.9.
|
// Section 12.2.5.4.9.
|
||||||
func inTableIM(p *parser) bool {
|
func inTableIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
case ErrorToken:
|
||||||
@ -1094,7 +1094,7 @@ func (p *parser) clearStackToContext(stopTags []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.11.
|
// Section 12.2.5.4.11.
|
||||||
func inCaptionIM(p *parser) bool {
|
func inCaptionIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case StartTagToken:
|
case StartTagToken:
|
||||||
@ -1134,7 +1134,7 @@ func inCaptionIM(p *parser) bool {
|
|||||||
return inBodyIM(p)
|
return inBodyIM(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.12.
|
// Section 12.2.5.4.12.
|
||||||
func inColumnGroupIM(p *parser) bool {
|
func inColumnGroupIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case CommentToken:
|
case CommentToken:
|
||||||
@ -1176,7 +1176,7 @@ func inColumnGroupIM(p *parser) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.13.
|
// Section 12.2.5.4.13.
|
||||||
func inTableBodyIM(p *parser) bool {
|
func inTableBodyIM(p *parser) bool {
|
||||||
var (
|
var (
|
||||||
add bool
|
add bool
|
||||||
@ -1232,7 +1232,7 @@ func inTableBodyIM(p *parser) bool {
|
|||||||
return inTableIM(p)
|
return inTableIM(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.14.
|
// Section 12.2.5.4.14.
|
||||||
func inRowIM(p *parser) bool {
|
func inRowIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
case ErrorToken:
|
||||||
@ -1291,7 +1291,7 @@ func inRowIM(p *parser) bool {
|
|||||||
return inTableIM(p)
|
return inTableIM(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.15.
|
// Section 12.2.5.4.15.
|
||||||
func inCellIM(p *parser) bool {
|
func inCellIM(p *parser) bool {
|
||||||
var (
|
var (
|
||||||
closeTheCellAndReprocess bool
|
closeTheCellAndReprocess bool
|
||||||
@ -1336,7 +1336,7 @@ func inCellIM(p *parser) bool {
|
|||||||
return inBodyIM(p)
|
return inBodyIM(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.16.
|
// Section 12.2.5.4.16.
|
||||||
func inSelectIM(p *parser) bool {
|
func inSelectIM(p *parser) bool {
|
||||||
endSelect := false
|
endSelect := false
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
@ -1413,7 +1413,7 @@ func inSelectIM(p *parser) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.18.
|
// Section 12.2.5.4.18.
|
||||||
func afterBodyIM(p *parser) bool {
|
func afterBodyIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
case ErrorToken:
|
||||||
@ -1443,7 +1443,7 @@ func afterBodyIM(p *parser) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.19.
|
// Section 12.2.5.4.19.
|
||||||
func inFramesetIM(p *parser) bool {
|
func inFramesetIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case CommentToken:
|
case CommentToken:
|
||||||
@ -1493,7 +1493,7 @@ func inFramesetIM(p *parser) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.20.
|
// Section 12.2.5.4.20.
|
||||||
func afterFramesetIM(p *parser) bool {
|
func afterFramesetIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case CommentToken:
|
case CommentToken:
|
||||||
@ -1532,7 +1532,7 @@ func afterFramesetIM(p *parser) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.21.
|
// Section 12.2.5.4.21.
|
||||||
func afterAfterBodyIM(p *parser) bool {
|
func afterAfterBodyIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case ErrorToken:
|
case ErrorToken:
|
||||||
@ -1555,7 +1555,7 @@ func afterAfterBodyIM(p *parser) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 11.2.5.4.22.
|
// Section 12.2.5.4.22.
|
||||||
func afterAfterFramesetIM(p *parser) bool {
|
func afterAfterFramesetIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
case CommentToken:
|
case CommentToken:
|
||||||
@ -1576,8 +1576,6 @@ func afterAfterFramesetIM(p *parser) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix up the other IM's section numbers to match the latest spec.
|
|
||||||
|
|
||||||
// Section 12.2.5.5.
|
// Section 12.2.5.5.
|
||||||
func inForeignContentIM(p *parser) bool {
|
func inForeignContentIM(p *parser) bool {
|
||||||
switch p.tok.Type {
|
switch p.tok.Type {
|
||||||
|
@ -247,7 +247,7 @@ func writeQuoted(w writer, s string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section 13.1.2, "Elements", gives this list of void elements. Void elements
|
// Section 12.1.2, "Elements", gives this list of void elements. Void elements
|
||||||
// are those that can't have any contents.
|
// are those that can't have any contents.
|
||||||
var voidElements = map[string]bool{
|
var voidElements = map[string]bool{
|
||||||
"area": true,
|
"area": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user