1
2
3
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 if strings.EqualFold(a.Val, "text/html") || strings.EqualFold(a.Val, "application/xhtml+xml") {
44 return true
45 }
46 }
47 }
48 }
49 case "svg":
50 switch n.Data {
51 case "desc", "foreignObject", "title":
52 return true
53 }
54 }
55 return false
56 }
57
58 func mathMLTextIntegrationPoint(n *Node) bool {
59 if n.Namespace != "math" {
60 return false
61 }
62 switch n.Data {
63 case "mi", "mo", "mn", "ms", "mtext":
64 return true
65 }
66 return false
67 }
68
69
70 var breakout = map[string]bool{
71 "b": true,
72 "big": true,
73 "blockquote": true,
74 "body": true,
75 "br": true,
76 "center": true,
77 "code": true,
78 "dd": true,
79 "div": true,
80 "dl": true,
81 "dt": true,
82 "em": true,
83 "embed": true,
84 "h1": true,
85 "h2": true,
86 "h3": true,
87 "h4": true,
88 "h5": true,
89 "h6": true,
90 "head": true,
91 "hr": true,
92 "i": true,
93 "img": true,
94 "li": true,
95 "listing": true,
96 "menu": true,
97 "meta": true,
98 "nobr": true,
99 "ol": true,
100 "p": true,
101 "pre": true,
102 "ruby": true,
103 "s": true,
104 "small": true,
105 "span": true,
106 "strong": true,
107 "strike": true,
108 "sub": true,
109 "sup": true,
110 "table": true,
111 "tt": true,
112 "u": true,
113 "ul": true,
114 "var": true,
115 }
116
117
118 var svgTagNameAdjustments = map[string]string{
119 "altglyph": "altGlyph",
120 "altglyphdef": "altGlyphDef",
121 "altglyphitem": "altGlyphItem",
122 "animatecolor": "animateColor",
123 "animatemotion": "animateMotion",
124 "animatetransform": "animateTransform",
125 "clippath": "clipPath",
126 "feblend": "feBlend",
127 "fecolormatrix": "feColorMatrix",
128 "fecomponenttransfer": "feComponentTransfer",
129 "fecomposite": "feComposite",
130 "feconvolvematrix": "feConvolveMatrix",
131 "fediffuselighting": "feDiffuseLighting",
132 "fedisplacementmap": "feDisplacementMap",
133 "fedistantlight": "feDistantLight",
134 "feflood": "feFlood",
135 "fefunca": "feFuncA",
136 "fefuncb": "feFuncB",
137 "fefuncg": "feFuncG",
138 "fefuncr": "feFuncR",
139 "fegaussianblur": "feGaussianBlur",
140 "feimage": "feImage",
141 "femerge": "feMerge",
142 "femergenode": "feMergeNode",
143 "femorphology": "feMorphology",
144 "feoffset": "feOffset",
145 "fepointlight": "fePointLight",
146 "fespecularlighting": "feSpecularLighting",
147 "fespotlight": "feSpotLight",
148 "fetile": "feTile",
149 "feturbulence": "feTurbulence",
150 "foreignobject": "foreignObject",
151 "glyphref": "glyphRef",
152 "lineargradient": "linearGradient",
153 "radialgradient": "radialGradient",
154 "textpath": "textPath",
155 }
156
157
158 var mathMLAttributeAdjustments = map[string]string{
159 "definitionurl": "definitionURL",
160 }
161
162 var svgAttributeAdjustments = map[string]string{
163 "attributename": "attributeName",
164 "attributetype": "attributeType",
165 "basefrequency": "baseFrequency",
166 "baseprofile": "baseProfile",
167 "calcmode": "calcMode",
168 "clippathunits": "clipPathUnits",
169 "diffuseconstant": "diffuseConstant",
170 "edgemode": "edgeMode",
171 "filterunits": "filterUnits",
172 "glyphref": "glyphRef",
173 "gradienttransform": "gradientTransform",
174 "gradientunits": "gradientUnits",
175 "kernelmatrix": "kernelMatrix",
176 "kernelunitlength": "kernelUnitLength",
177 "keypoints": "keyPoints",
178 "keysplines": "keySplines",
179 "keytimes": "keyTimes",
180 "lengthadjust": "lengthAdjust",
181 "limitingconeangle": "limitingConeAngle",
182 "markerheight": "markerHeight",
183 "markerunits": "markerUnits",
184 "markerwidth": "markerWidth",
185 "maskcontentunits": "maskContentUnits",
186 "maskunits": "maskUnits",
187 "numoctaves": "numOctaves",
188 "pathlength": "pathLength",
189 "patterncontentunits": "patternContentUnits",
190 "patterntransform": "patternTransform",
191 "patternunits": "patternUnits",
192 "pointsatx": "pointsAtX",
193 "pointsaty": "pointsAtY",
194 "pointsatz": "pointsAtZ",
195 "preservealpha": "preserveAlpha",
196 "preserveaspectratio": "preserveAspectRatio",
197 "primitiveunits": "primitiveUnits",
198 "refx": "refX",
199 "refy": "refY",
200 "repeatcount": "repeatCount",
201 "repeatdur": "repeatDur",
202 "requiredextensions": "requiredExtensions",
203 "requiredfeatures": "requiredFeatures",
204 "specularconstant": "specularConstant",
205 "specularexponent": "specularExponent",
206 "spreadmethod": "spreadMethod",
207 "startoffset": "startOffset",
208 "stddeviation": "stdDeviation",
209 "stitchtiles": "stitchTiles",
210 "surfacescale": "surfaceScale",
211 "systemlanguage": "systemLanguage",
212 "tablevalues": "tableValues",
213 "targetx": "targetX",
214 "targety": "targetY",
215 "textlength": "textLength",
216 "viewbox": "viewBox",
217 "viewtarget": "viewTarget",
218 "xchannelselector": "xChannelSelector",
219 "ychannelselector": "yChannelSelector",
220 "zoomandpan": "zoomAndPan",
221 }
222
View as plain text