github.com/vugu/vugu@v0.3.6-0.20240430171613-3f6f402e014b/internal/htmlx/const.go (about)

     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 htmlx
     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  	"isindex":    true, // The 'isindex' element has been removed, but keep it for backwards compatibility.
    56  	"keygen":     true,
    57  	"li":         true,
    58  	"link":       true,
    59  	"listing":    true,
    60  	"main":       true,
    61  	"marquee":    true,
    62  	"menu":       true,
    63  	"meta":       true,
    64  	"nav":        true,
    65  	"noembed":    true,
    66  	"noframes":   true,
    67  	"noscript":   true,
    68  	"object":     true,
    69  	"ol":         true,
    70  	"p":          true,
    71  	"param":      true,
    72  	"plaintext":  true,
    73  	"pre":        true,
    74  	"script":     true,
    75  	"section":    true,
    76  	"select":     true,
    77  	"source":     true,
    78  	"style":      true,
    79  	"summary":    true,
    80  	"table":      true,
    81  	"tbody":      true,
    82  	"td":         true,
    83  	"template":   true,
    84  	"textarea":   true,
    85  	"tfoot":      true,
    86  	"th":         true,
    87  	"thead":      true,
    88  	"title":      true,
    89  	"tr":         true,
    90  	"track":      true,
    91  	"ul":         true,
    92  	"wbr":        true,
    93  	"xmp":        true,
    94  }
    95  
    96  func isSpecialElement(element *Node) bool {
    97  	switch element.Namespace {
    98  	case "", "html":
    99  		return isSpecialElementMap[element.Data]
   100  	case "math":
   101  		switch element.Data {
   102  		case "mi", "mo", "mn", "ms", "mtext", "annotation-xml":
   103  			return true
   104  		}
   105  	case "svg":
   106  		switch element.Data {
   107  		case "foreignObject", "desc", "title":
   108  			return true
   109  		}
   110  	}
   111  	return false
   112  }