本站源代码
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.

113 lines
2.6KB

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