util.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // use lazy_static::lazy_static;
  2. use once_cell::sync::Lazy;
  3. use std::collections::hash_set::HashSet;
  4. static VALID_TAGS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
  5. [
  6. "a",
  7. "abbr",
  8. "address",
  9. "area",
  10. "article",
  11. "aside",
  12. "audio",
  13. "b",
  14. "base",
  15. "bdi",
  16. "bdo",
  17. "big",
  18. "blockquote",
  19. "body",
  20. "br",
  21. "button",
  22. "canvas",
  23. "caption",
  24. "cite",
  25. "code",
  26. "col",
  27. "colgroup",
  28. "command",
  29. "data",
  30. "datalist",
  31. "dd",
  32. "del",
  33. "details",
  34. "dfn",
  35. "dialog",
  36. "div",
  37. "dl",
  38. "dt",
  39. "em",
  40. "embed",
  41. "fieldset",
  42. "figcaption",
  43. "figure",
  44. "footer",
  45. "form",
  46. "h1",
  47. "h2",
  48. "h3",
  49. "h4",
  50. "h5",
  51. "h6",
  52. "head",
  53. "header",
  54. "hr",
  55. "html",
  56. "i",
  57. "iframe",
  58. "img",
  59. "input",
  60. "ins",
  61. "kbd",
  62. "keygen",
  63. "label",
  64. "legend",
  65. "li",
  66. "link",
  67. "main",
  68. "map",
  69. "mark",
  70. "menu",
  71. "menuitem",
  72. "meta",
  73. "meter",
  74. "nav",
  75. "noscript",
  76. "object",
  77. "ol",
  78. "optgroup",
  79. "option",
  80. "output",
  81. "p",
  82. "param",
  83. "picture",
  84. "pre",
  85. "progress",
  86. "q",
  87. "rp",
  88. "rt",
  89. "ruby",
  90. "s",
  91. "samp",
  92. "script",
  93. "section",
  94. "select",
  95. "small",
  96. "source",
  97. "span",
  98. "strong",
  99. "style",
  100. "sub",
  101. "summary",
  102. "sup",
  103. "table",
  104. "tbody",
  105. "td",
  106. "textarea",
  107. "tfoot",
  108. "th",
  109. "thead",
  110. "time",
  111. "title",
  112. "tr",
  113. "track",
  114. "u",
  115. "ul",
  116. "var",
  117. "video",
  118. "wbr",
  119. ]
  120. .iter()
  121. .cloned()
  122. .collect()
  123. });
  124. /// Whether or not this tag is valid
  125. ///
  126. /// ```
  127. /// use html_validation::is_valid_tag;
  128. ///
  129. /// assert_eq!(is_valid_tag("br"), true);
  130. ///
  131. /// assert_eq!(is_valid_tag("random"), false);
  132. /// ```
  133. pub fn is_valid_tag(tag: &str) -> bool {
  134. VALID_TAGS.contains(tag)
  135. }