foreign.go 6.2 KB

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