foreign.go 6.8 KB

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