Nigel Tao | ea127e8 | 2013-02-11 11:55:20 +1100 | [diff] [blame] | 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 | |
namusyaka | 2e7f24a | 2018-02-15 22:39:58 +0900 | [diff] [blame] | 70 | // Section 12.2.6.5. |
Nigel Tao | ea127e8 | 2013-02-11 11:55:20 +1100 | [diff] [blame] | 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 | |
namusyaka | 2e7f24a | 2018-02-15 22:39:58 +0900 | [diff] [blame] | 118 | // Section 12.2.6.5. |
Nigel Tao | ea127e8 | 2013-02-11 11:55:20 +1100 | [diff] [blame] | 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 | |
namusyaka | 2e7f24a | 2018-02-15 22:39:58 +0900 | [diff] [blame] | 158 | // Section 12.2.6.1 |
Nigel Tao | ea127e8 | 2013-02-11 11:55:20 +1100 | [diff] [blame] | 159 | var mathMLAttributeAdjustments = map[string]string{ |
| 160 | "definitionurl": "definitionURL", |
| 161 | } |
| 162 | |
| 163 | var svgAttributeAdjustments = map[string]string{ |
Kunpei Sakai | d65d470 | 2020-10-19 00:57:28 +0900 | [diff] [blame] | 164 | "attributename": "attributeName", |
| 165 | "attributetype": "attributeType", |
| 166 | "basefrequency": "baseFrequency", |
| 167 | "baseprofile": "baseProfile", |
| 168 | "calcmode": "calcMode", |
| 169 | "clippathunits": "clipPathUnits", |
| 170 | "diffuseconstant": "diffuseConstant", |
| 171 | "edgemode": "edgeMode", |
| 172 | "filterunits": "filterUnits", |
| 173 | "glyphref": "glyphRef", |
| 174 | "gradienttransform": "gradientTransform", |
| 175 | "gradientunits": "gradientUnits", |
| 176 | "kernelmatrix": "kernelMatrix", |
| 177 | "kernelunitlength": "kernelUnitLength", |
| 178 | "keypoints": "keyPoints", |
| 179 | "keysplines": "keySplines", |
| 180 | "keytimes": "keyTimes", |
| 181 | "lengthadjust": "lengthAdjust", |
| 182 | "limitingconeangle": "limitingConeAngle", |
| 183 | "markerheight": "markerHeight", |
| 184 | "markerunits": "markerUnits", |
| 185 | "markerwidth": "markerWidth", |
| 186 | "maskcontentunits": "maskContentUnits", |
| 187 | "maskunits": "maskUnits", |
| 188 | "numoctaves": "numOctaves", |
| 189 | "pathlength": "pathLength", |
| 190 | "patterncontentunits": "patternContentUnits", |
| 191 | "patterntransform": "patternTransform", |
| 192 | "patternunits": "patternUnits", |
| 193 | "pointsatx": "pointsAtX", |
| 194 | "pointsaty": "pointsAtY", |
| 195 | "pointsatz": "pointsAtZ", |
| 196 | "preservealpha": "preserveAlpha", |
| 197 | "preserveaspectratio": "preserveAspectRatio", |
| 198 | "primitiveunits": "primitiveUnits", |
| 199 | "refx": "refX", |
| 200 | "refy": "refY", |
| 201 | "repeatcount": "repeatCount", |
| 202 | "repeatdur": "repeatDur", |
| 203 | "requiredextensions": "requiredExtensions", |
| 204 | "requiredfeatures": "requiredFeatures", |
| 205 | "specularconstant": "specularConstant", |
| 206 | "specularexponent": "specularExponent", |
| 207 | "spreadmethod": "spreadMethod", |
| 208 | "startoffset": "startOffset", |
| 209 | "stddeviation": "stdDeviation", |
| 210 | "stitchtiles": "stitchTiles", |
| 211 | "surfacescale": "surfaceScale", |
| 212 | "systemlanguage": "systemLanguage", |
| 213 | "tablevalues": "tableValues", |
| 214 | "targetx": "targetX", |
| 215 | "targety": "targetY", |
| 216 | "textlength": "textLength", |
| 217 | "viewbox": "viewBox", |
| 218 | "viewtarget": "viewTarget", |
| 219 | "xchannelselector": "xChannelSelector", |
| 220 | "ychannelselector": "yChannelSelector", |
| 221 | "zoomandpan": "zoomAndPan", |
Nigel Tao | ea127e8 | 2013-02-11 11:55:20 +1100 | [diff] [blame] | 222 | } |