const.go raw

   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  // Section 12.2.4.2 of the HTML5 specification says "The following elements
   8  // have varying levels of special parsing rules".
   9  // https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements
  10  var isSpecialElementMap = map[string]bool{
  11  	"address":    true,
  12  	"applet":     true,
  13  	"area":       true,
  14  	"article":    true,
  15  	"aside":      true,
  16  	"base":       true,
  17  	"basefont":   true,
  18  	"bgsound":    true,
  19  	"blockquote": true,
  20  	"body":       true,
  21  	"br":         true,
  22  	"button":     true,
  23  	"caption":    true,
  24  	"center":     true,
  25  	"col":        true,
  26  	"colgroup":   true,
  27  	"dd":         true,
  28  	"details":    true,
  29  	"dir":        true,
  30  	"div":        true,
  31  	"dl":         true,
  32  	"dt":         true,
  33  	"embed":      true,
  34  	"fieldset":   true,
  35  	"figcaption": true,
  36  	"figure":     true,
  37  	"footer":     true,
  38  	"form":       true,
  39  	"frame":      true,
  40  	"frameset":   true,
  41  	"h1":         true,
  42  	"h2":         true,
  43  	"h3":         true,
  44  	"h4":         true,
  45  	"h5":         true,
  46  	"h6":         true,
  47  	"head":       true,
  48  	"header":     true,
  49  	"hgroup":     true,
  50  	"hr":         true,
  51  	"html":       true,
  52  	"iframe":     true,
  53  	"img":        true,
  54  	"input":      true,
  55  	"keygen":     true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility.
  56  	"li":         true,
  57  	"link":       true,
  58  	"listing":    true,
  59  	"main":       true,
  60  	"marquee":    true,
  61  	"menu":       true,
  62  	"meta":       true,
  63  	"nav":        true,
  64  	"noembed":    true,
  65  	"noframes":   true,
  66  	"noscript":   true,
  67  	"object":     true,
  68  	"ol":         true,
  69  	"p":          true,
  70  	"param":      true,
  71  	"plaintext":  true,
  72  	"pre":        true,
  73  	"script":     true,
  74  	"section":    true,
  75  	"select":     true,
  76  	"source":     true,
  77  	"style":      true,
  78  	"summary":    true,
  79  	"table":      true,
  80  	"tbody":      true,
  81  	"td":         true,
  82  	"template":   true,
  83  	"textarea":   true,
  84  	"tfoot":      true,
  85  	"th":         true,
  86  	"thead":      true,
  87  	"title":      true,
  88  	"tr":         true,
  89  	"track":      true,
  90  	"ul":         true,
  91  	"wbr":        true,
  92  	"xmp":        true,
  93  }
  94  
  95  func isSpecialElement(element *Node) bool {
  96  	switch element.Namespace {
  97  	case "", "html":
  98  		return isSpecialElementMap[element.Data]
  99  	case "math":
 100  		switch element.Data {
 101  		case "mi", "mo", "mn", "ms", "mtext", "annotation-xml":
 102  			return true
 103  		}
 104  	case "svg":
 105  		switch element.Data {
 106  		case "foreignObject", "desc", "title":
 107  			return true
 108  		}
 109  	}
 110  	return false
 111  }
 112