1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package html
6
7import (
8	"strings"
9)
10
11func adjustAttributeNames(aa []Attribute, nameMap map[string]string) {
12	for i := range aa {
13		if newName, ok := nameMap[aa[i].Key]; ok {
14			aa[i].Key = newName
15		}
16	}
17}
18
19func adjustForeignAttributes(aa []Attribute) {
20	for i, a := range aa {
21		if a.Key == "" || a.Key[0] != 'x' {
22			continue
23		}
24		switch a.Key {
25		case "xlink:actuate", "xlink:arcrole", "xlink:href", "xlink:role", "xlink:show",
26			"xlink:title", "xlink:type", "xml:base", "xml:lang", "xml:space", "xmlns:xlink":
27			j := strings.Index(a.Key, ":")
28			aa[i].Namespace = a.Key[:j]
29			aa[i].Key = a.Key[j+1:]
30		}
31	}
32}
33
34func htmlIntegrationPoint(n *Node) bool {
35	if n.Type != ElementNode {
36		return false
37	}
38	switch n.Namespace {
39	case "math":
40		if n.Data == "annotation-xml" {
41			for _, a := range n.Attr {
42				if a.Key == "encoding" {
43					val := strings.ToLower(a.Val)
44					if val == "text/html" || val == "application/xhtml+xml" {
45						return true
46					}
47				}
48			}
49		}
50	case "svg":
51		switch n.Data {
52		case "desc", "foreignObject", "title":
53			return true
54		}
55	}
56	return false
57}
58
59func mathMLTextIntegrationPoint(n *Node) bool {
60	if n.Namespace != "math" {
61		return false
62	}
63	switch n.Data {
64	case "mi", "mo", "mn", "ms", "mtext":
65		return true
66	}
67	return false
68}
69
70// Section 12.2.6.5.
71var breakout = map[string]bool{
72	"b":          true,
73	"big":        true,
74	"blockquote": true,
75	"body":       true,
76	"br":         true,
77	"center":     true,
78	"code":       true,
79	"dd":         true,
80	"div":        true,
81	"dl":         true,
82	"dt":         true,
83	"em":         true,
84	"embed":      true,
85	"h1":         true,
86	"h2":         true,
87	"h3":         true,
88	"h4":         true,
89	"h5":         true,
90	"h6":         true,
91	"head":       true,
92	"hr":         true,
93	"i":          true,
94	"img":        true,
95	"li":         true,
96	"listing":    true,
97	"menu":       true,
98	"meta":       true,
99	"nobr":       true,
100	"ol":         true,
101	"p":          true,
102	"pre":        true,
103	"ruby":       true,
104	"s":          true,
105	"small":      true,
106	"span":       true,
107	"strong":     true,
108	"strike":     true,
109	"sub":        true,
110	"sup":        true,
111	"table":      true,
112	"tt":         true,
113	"u":          true,
114	"ul":         true,
115	"var":        true,
116}
117
118// Section 12.2.6.5.
119var svgTagNameAdjustments = map[string]string{
120	"altglyph":            "altGlyph",
121	"altglyphdef":         "altGlyphDef",
122	"altglyphitem":        "altGlyphItem",
123	"animatecolor":        "animateColor",
124	"animatemotion":       "animateMotion",
125	"animatetransform":    "animateTransform",
126	"clippath":            "clipPath",
127	"feblend":             "feBlend",
128	"fecolormatrix":       "feColorMatrix",
129	"fecomponenttransfer": "feComponentTransfer",
130	"fecomposite":         "feComposite",
131	"feconvolvematrix":    "feConvolveMatrix",
132	"fediffuselighting":   "feDiffuseLighting",
133	"fedisplacementmap":   "feDisplacementMap",
134	"fedistantlight":      "feDistantLight",
135	"feflood":             "feFlood",
136	"fefunca":             "feFuncA",
137	"fefuncb":             "feFuncB",
138	"fefuncg":             "feFuncG",
139	"fefuncr":             "feFuncR",
140	"fegaussianblur":      "feGaussianBlur",
141	"feimage":             "feImage",
142	"femerge":             "feMerge",
143	"femergenode":         "feMergeNode",
144	"femorphology":        "feMorphology",
145	"feoffset":            "feOffset",
146	"fepointlight":        "fePointLight",
147	"fespecularlighting":  "feSpecularLighting",
148	"fespotlight":         "feSpotLight",
149	"fetile":              "feTile",
150	"feturbulence":        "feTurbulence",
151	"foreignobject":       "foreignObject",
152	"glyphref":            "glyphRef",
153	"lineargradient":      "linearGradient",
154	"radialgradient":      "radialGradient",
155	"textpath":            "textPath",
156}
157
158// Section 12.2.6.1
159var mathMLAttributeAdjustments = map[string]string{
160	"definitionurl": "definitionURL",
161}
162
163var svgAttributeAdjustments = map[string]string{
164	"attributename":             "attributeName",
165	"attributetype":             "attributeType",
166	"basefrequency":             "baseFrequency",
167	"baseprofile":               "baseProfile",
168	"calcmode":                  "calcMode",
169	"clippathunits":             "clipPathUnits",
170	"contentscripttype":         "contentScriptType",
171	"contentstyletype":          "contentStyleType",
172	"diffuseconstant":           "diffuseConstant",
173	"edgemode":                  "edgeMode",
174	"externalresourcesrequired": "externalResourcesRequired",
175	"filterunits":               "filterUnits",
176	"glyphref":                  "glyphRef",
177	"gradienttransform":         "gradientTransform",
178	"gradientunits":             "gradientUnits",
179	"kernelmatrix":              "kernelMatrix",
180	"kernelunitlength":          "kernelUnitLength",
181	"keypoints":                 "keyPoints",
182	"keysplines":                "keySplines",
183	"keytimes":                  "keyTimes",
184	"lengthadjust":              "lengthAdjust",
185	"limitingconeangle":         "limitingConeAngle",
186	"markerheight":              "markerHeight",
187	"markerunits":               "markerUnits",
188	"markerwidth":               "markerWidth",
189	"maskcontentunits":          "maskContentUnits",
190	"maskunits":                 "maskUnits",
191	"numoctaves":                "numOctaves",
192	"pathlength":                "pathLength",
193	"patterncontentunits":       "patternContentUnits",
194	"patterntransform":          "patternTransform",
195	"patternunits":              "patternUnits",
196	"pointsatx":                 "pointsAtX",
197	"pointsaty":                 "pointsAtY",
198	"pointsatz":                 "pointsAtZ",
199	"preservealpha":             "preserveAlpha",
200	"preserveaspectratio":       "preserveAspectRatio",
201	"primitiveunits":            "primitiveUnits",
202	"refx":                      "refX",
203	"refy":                      "refY",
204	"repeatcount":               "repeatCount",
205	"repeatdur":                 "repeatDur",
206	"requiredextensions":        "requiredExtensions",
207	"requiredfeatures":          "requiredFeatures",
208	"specularconstant":          "specularConstant",
209	"specularexponent":          "specularExponent",
210	"spreadmethod":              "spreadMethod",
211	"startoffset":               "startOffset",
212	"stddeviation":              "stdDeviation",
213	"stitchtiles":               "stitchTiles",
214	"surfacescale":              "surfaceScale",
215	"systemlanguage":            "systemLanguage",
216	"tablevalues":               "tableValues",
217	"targetx":                   "targetX",
218	"targety":                   "targetY",
219	"textlength":                "textLength",
220	"viewbox":                   "viewBox",
221	"viewtarget":                "viewTarget",
222	"xchannelselector":          "xChannelSelector",
223	"ychannelselector":          "yChannelSelector",
224	"zoomandpan":                "zoomAndPan",
225}
226