You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.5 KiB

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