HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
prebuilts
go
darwin-x86
src
html
template
context.go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package template import ( "fmt" ) // context describes the state an HTML parser must be in when it reaches the // portion of HTML produced by evaluating a particular template node. // // The zero value of type context is the start context for a template that // produces an HTML fragment as defined at // http://www.w3.org/TR/html5/syntax.html#the-end // where the context element is null. type context struct { state state delim delim urlPart urlPart jsCtx jsCtx attr attr element element err *Error } func (c context) String() string { return fmt.Sprintf("{%v %v %v %v %v %v %v}", c.state, c.delim, c.urlPart, c.jsCtx, c.attr, c.element, c.err) } // eq reports whether two contexts are equal. func (c context) eq(d context) bool { return c.state == d.state && c.delim == d.delim && c.urlPart == d.urlPart && c.jsCtx == d.jsCtx && c.attr == d.attr && c.element == d.element && c.err == d.err } // mangle produces an identifier that includes a suffix that distinguishes it // from template names mangled with different contexts. func (c context) mangle(templateName string) string { // The mangled name for the default context is the input templateName. if c.state == stateText { return templateName } s := templateName + "$htmltemplate_" + c.state.String() if c.delim != 0 { s += "_" + c.delim.String() } if c.urlPart != 0 { s += "_" + c.urlPart.String() } if c.jsCtx != 0 { s += "_" + c.jsCtx.String() } if c.attr != 0 { s += "_" + c.attr.String() } if c.element != 0 { s += "_" + c.element.String() } return s } // state describes a high-level HTML parser state. // // It bounds the top of the element stack, and by extension the HTML insertion // mode, but also contains state that does not correspond to anything in the // HTML5 parsing algorithm because a single token production in the HTML // grammar may contain embedded actions in a template. For instance, the quoted // HTML attribute produced by //
// is a single token in HTML's grammar but in a template spans several nodes. type state uint8 const ( // stateText is parsed character data. An HTML parser is in // this state when its parse position is outside an HTML tag, // directive, comment, and special element body. stateText state = iota // stateTag occurs before an HTML attribute or the end of a tag. stateTag // stateAttrName occurs inside an attribute name. // It occurs between the ^'s in ` ^name^ = value`. stateAttrName // stateAfterName occurs after an attr name has ended but before any // equals sign. It occurs between the ^'s in ` name^ ^= value`. stateAfterName // stateBeforeValue occurs after the equals sign but before the value. // It occurs between the ^'s in ` name =^ ^value`. stateBeforeValue // stateHTMLCmt occurs inside an . stateHTMLCmt // stateRCDATA occurs inside an RCDATA element (
or
) // as described at http://www.w3.org/TR/html5/syntax.html#elements-0 stateRCDATA // stateAttr occurs inside an HTML attribute whose content is text. stateAttr // stateURL occurs inside an HTML attribute whose content is a URL. stateURL // stateSrcset occurs inside an HTML srcset attribute. stateSrcset // stateJS occurs inside an event handler or script element. stateJS // stateJSDqStr occurs inside a JavaScript double quoted string. stateJSDqStr // stateJSSqStr occurs inside a JavaScript single quoted string. stateJSSqStr // stateJSRegexp occurs inside a JavaScript regexp literal. stateJSRegexp // stateJSBlockCmt occurs inside a JavaScript /* block comment */. stateJSBlockCmt // stateJSLineCmt occurs inside a JavaScript // line comment. stateJSLineCmt // stateCSS occurs inside a