html.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. """HTML constants."""
  2. # See https://html.spec.whatwg.org/#elements-3.
  3. ELEMENTS = {
  4. "a",
  5. "abbr",
  6. "address",
  7. "area",
  8. "article",
  9. "aside",
  10. "audio",
  11. "b",
  12. "base",
  13. "bdi",
  14. "bdo",
  15. "blockquote",
  16. "body",
  17. "br",
  18. "button",
  19. "canvas",
  20. "caption",
  21. "cite",
  22. "code",
  23. "col",
  24. "colgroup",
  25. "data",
  26. "datalist",
  27. "dd",
  28. "del",
  29. "details",
  30. "dfn",
  31. "dialog",
  32. "div",
  33. "dl",
  34. "dt",
  35. "em",
  36. "embed",
  37. "fieldset",
  38. "figcaption",
  39. "figure",
  40. "footer",
  41. "form",
  42. "h1",
  43. "h2",
  44. "h3",
  45. "h4",
  46. "h5",
  47. "h6",
  48. "head",
  49. "header",
  50. "hr",
  51. "html",
  52. "i",
  53. "iframe",
  54. "img",
  55. "input",
  56. "ins",
  57. "kbd",
  58. "label",
  59. "legend",
  60. "li",
  61. "link",
  62. "main",
  63. "map",
  64. "mark",
  65. "math",
  66. "menu",
  67. "meta",
  68. "meter",
  69. "nav",
  70. "noscript",
  71. "object",
  72. "ol",
  73. "optgroup",
  74. "option",
  75. "output",
  76. "p",
  77. "picture",
  78. "portal",
  79. "pre",
  80. "progress",
  81. "q",
  82. "rp",
  83. "rt",
  84. "ruby",
  85. "s",
  86. "samp",
  87. "script",
  88. "section",
  89. "select",
  90. "slot",
  91. "small",
  92. "source",
  93. "span",
  94. "strong",
  95. "style",
  96. "sub",
  97. "summary",
  98. "sup",
  99. "svg",
  100. "table",
  101. "tbody",
  102. "td",
  103. "template",
  104. "textarea",
  105. "tfoot",
  106. "th",
  107. "thead",
  108. "time",
  109. "title",
  110. "tr",
  111. "track",
  112. "u",
  113. "ul",
  114. "var",
  115. "video",
  116. "wbr",
  117. }
  118. # See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes.
  119. ATTR_TO_ELEMENTS = {
  120. "accept": {"form", "input"},
  121. "accept-charset": {"form"},
  122. "accesskey": ELEMENTS,
  123. "action": {"form"},
  124. "align": {
  125. "applet",
  126. "caption",
  127. "col",
  128. "colgroup",
  129. "hr",
  130. "iframe",
  131. "img",
  132. "table",
  133. "tbody",
  134. "td",
  135. "tfoot",
  136. "th",
  137. "thead",
  138. "tr",
  139. },
  140. "allow": {"iframe"},
  141. "alt": {"applet", "area", "img", "input"},
  142. "async": {"script"},
  143. "autocapitalize": ELEMENTS,
  144. "autocomplete": {"form", "input", "select", "textarea"},
  145. "autofocus": {"button", "input", "keygen", "select", "textarea"},
  146. "autoplay": {"audio", "video"},
  147. "background": {"body", "table", "td", "th"},
  148. "bgcolor": {
  149. "body",
  150. "col",
  151. "colgroup",
  152. "marquee",
  153. "table",
  154. "tbody",
  155. "tfoot",
  156. "td",
  157. "th",
  158. "tr",
  159. },
  160. "border": {"img", "object", "table"},
  161. "buffered": {"audio", "video"},
  162. "capture": {"input"},
  163. "challenge": {"keygen"},
  164. "charset": {"meta", "script"},
  165. "checked": {"input"},
  166. "cite": {"blockquote", "del", "ins", "q"},
  167. "class": ELEMENTS,
  168. "code": {"applet"},
  169. "codebase": {"applet"},
  170. "color": {"font", "hr"},
  171. "cols": {"textarea"},
  172. "colspan": {"td", "th"},
  173. "content": {"meta"},
  174. "contenteditable": ELEMENTS,
  175. "contextmenu": ELEMENTS,
  176. "controls": {"audio", "video"},
  177. "coords": {"area"},
  178. "crossorigin": {"audio", "img", "link", "script", "video"},
  179. "csp": {"iframe"},
  180. "data": {"object"},
  181. "datetime": {"del", "ins", "time"},
  182. "decoding": {"img"},
  183. "default": {"track"},
  184. "defer": {"script"},
  185. "dir": ELEMENTS,
  186. "dirname": {"input", "textarea"},
  187. "disabled": {
  188. "button",
  189. "fieldset",
  190. "input",
  191. "keygen",
  192. "optgroup",
  193. "option",
  194. "select",
  195. "textarea",
  196. },
  197. "download": {"a", "area"},
  198. "draggable": ELEMENTS,
  199. "enctype": {"form"},
  200. "enterkeyhint": ELEMENTS,
  201. "for": {"label", "output"},
  202. "form": {
  203. "button",
  204. "fieldset",
  205. "input",
  206. "keygen",
  207. "label",
  208. "meter",
  209. "object",
  210. "output",
  211. "progress",
  212. "select",
  213. "textarea",
  214. },
  215. "formaction": {"button", "input"},
  216. "formenctype": {"button", "input"},
  217. "formmethod": {"button", "input"},
  218. "formnovalidate": {"button", "input"},
  219. "formtarget": {"button", "input"},
  220. "headers": {"td", "th"},
  221. "height": {"canvas", "embed", "iframe", "img", "input", "object", "video"},
  222. "hidden": ELEMENTS,
  223. "high": {"meter"},
  224. "href": {"a", "area", "base", "link"},
  225. "hreflang": {"a", "area", "link"},
  226. "http-equiv": {"meta"},
  227. "icon": {"command"},
  228. "id": ELEMENTS,
  229. "integrity": {"link", "script"},
  230. "intrinsicsize": {"img"},
  231. "inputmode": ELEMENTS,
  232. "ismap": {"img"},
  233. "itemprop": ELEMENTS,
  234. "keytype": {"keygen"},
  235. "kind": {"track"},
  236. "label": {"optgroup", "option", "track"},
  237. "lang": ELEMENTS,
  238. "language": {"script"},
  239. "loading": {"img", "iframe"},
  240. "list": {"input"},
  241. "loop": {"audio", "bgsound", "marquee", "video"},
  242. "low": {"meter"},
  243. "manifest": {"html"},
  244. "max": {"input", "meter", "progress"},
  245. "maxlength": {"input", "textarea"},
  246. "minlength": {"input", "textarea"},
  247. "media": {"a", "area", "link", "source", "style"},
  248. "method": {"form"},
  249. "min": {"input", "meter"},
  250. "multiple": {"input", "select"},
  251. "muted": {"audio", "video"},
  252. "name": {
  253. "button",
  254. "form",
  255. "fieldset",
  256. "iframe",
  257. "input",
  258. "keygen",
  259. "object",
  260. "output",
  261. "select",
  262. "textarea",
  263. "map",
  264. "meta",
  265. "param",
  266. },
  267. "novalidate": {"form"},
  268. "open": {"details", "dialog"},
  269. "optimum": {"meter"},
  270. "pattern": {"input"},
  271. "ping": {"a", "area"},
  272. "placeholder": {"input", "textarea"},
  273. "playsinline": {"video"},
  274. "poster": {"video"},
  275. "preload": {"audio", "video"},
  276. "readonly": {"input", "textarea"},
  277. "referrerpolicy": {"a", "area", "iframe", "img", "link", "script"},
  278. "rel": {"a", "area", "link"},
  279. "required": {"input", "select", "textarea"},
  280. "reversed": {"ol"},
  281. "role": ELEMENTS,
  282. "rows": {"textarea"},
  283. "rowspan": {"td", "th"},
  284. "sandbox": {"iframe"},
  285. "scope": {"th"},
  286. "scoped": {"style"},
  287. "selected": {"option"},
  288. "shape": {"a", "area"},
  289. "size": {"input", "select"},
  290. "sizes": {"link", "img", "source"},
  291. "slot": ELEMENTS,
  292. "span": {"col", "colgroup"},
  293. "spellcheck": ELEMENTS,
  294. "src": {
  295. "audio",
  296. "embed",
  297. "iframe",
  298. "img",
  299. "input",
  300. "script",
  301. "source",
  302. "track",
  303. "video",
  304. },
  305. "srcdoc": {"iframe"},
  306. "srclang": {"track"},
  307. "srcset": {"img", "source"},
  308. "start": {"ol"},
  309. "step": {"input"},
  310. "style": ELEMENTS,
  311. "summary": {"table"},
  312. "tabindex": ELEMENTS,
  313. "target": {"a", "area", "base", "form"},
  314. "title": ELEMENTS,
  315. "translate": ELEMENTS,
  316. "type": {
  317. "button",
  318. "input",
  319. "embed",
  320. "object",
  321. "ol",
  322. "script",
  323. "source",
  324. "style",
  325. "menu",
  326. "link",
  327. },
  328. "usemap": {"img", "input", "object"},
  329. "value": {
  330. "button",
  331. "data",
  332. "input",
  333. "li",
  334. "meter",
  335. "option",
  336. "progress",
  337. "param",
  338. },
  339. "width": {"canvas", "embed", "iframe", "img", "input", "object", "video"},
  340. "wrap": {"textarea"},
  341. }