]>
Commit | Line | Data |
---|---|---|
c680a8e1 RS |
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 | ||
5 | package html | |
6 | ||
7 | import ( | |
8 | "strings" | |
9 | ) | |
10 | ||
11 | func 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 | ||
19 | func 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 | ||
34 | func 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 | ||
59 | func 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.5.5. | |
71 | var 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.5.5. | |
119 | var 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.5.1 | |
159 | var mathMLAttributeAdjustments = map[string]string{ | |
160 | "definitionurl": "definitionURL", | |
161 | } | |
162 | ||
163 | var 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 | "filterres": "filterRes", | |
176 | "filterunits": "filterUnits", | |
177 | "glyphref": "glyphRef", | |
178 | "gradienttransform": "gradientTransform", | |
179 | "gradientunits": "gradientUnits", | |
180 | "kernelmatrix": "kernelMatrix", | |
181 | "kernelunitlength": "kernelUnitLength", | |
182 | "keypoints": "keyPoints", | |
183 | "keysplines": "keySplines", | |
184 | "keytimes": "keyTimes", | |
185 | "lengthadjust": "lengthAdjust", | |
186 | "limitingconeangle": "limitingConeAngle", | |
187 | "markerheight": "markerHeight", | |
188 | "markerunits": "markerUnits", | |
189 | "markerwidth": "markerWidth", | |
190 | "maskcontentunits": "maskContentUnits", | |
191 | "maskunits": "maskUnits", | |
192 | "numoctaves": "numOctaves", | |
193 | "pathlength": "pathLength", | |
194 | "patterncontentunits": "patternContentUnits", | |
195 | "patterntransform": "patternTransform", | |
196 | "patternunits": "patternUnits", | |
197 | "pointsatx": "pointsAtX", | |
198 | "pointsaty": "pointsAtY", | |
199 | "pointsatz": "pointsAtZ", | |
200 | "preservealpha": "preserveAlpha", | |
201 | "preserveaspectratio": "preserveAspectRatio", | |
202 | "primitiveunits": "primitiveUnits", | |
203 | "refx": "refX", | |
204 | "refy": "refY", | |
205 | "repeatcount": "repeatCount", | |
206 | "repeatdur": "repeatDur", | |
207 | "requiredextensions": "requiredExtensions", | |
208 | "requiredfeatures": "requiredFeatures", | |
209 | "specularconstant": "specularConstant", | |
210 | "specularexponent": "specularExponent", | |
211 | "spreadmethod": "spreadMethod", | |
212 | "startoffset": "startOffset", | |
213 | "stddeviation": "stdDeviation", | |
214 | "stitchtiles": "stitchTiles", | |
215 | "surfacescale": "surfaceScale", | |
216 | "systemlanguage": "systemLanguage", | |
217 | "tablevalues": "tableValues", | |
218 | "targetx": "targetX", | |
219 | "targety": "targetY", | |
220 | "textlength": "textLength", | |
221 | "viewbox": "viewBox", | |
222 | "viewtarget": "viewTarget", | |
223 | "xchannelselector": "xChannelSelector", | |
224 | "ychannelselector": "yChannelSelector", | |
225 | "zoomandpan": "zoomAndPan", | |
226 | } |