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