Commit c271a044 authored by David Sveningsson's avatar David Sveningsson

feat(meta): new property `scriptSupporting`

parent 22a10ab3
......@@ -36,6 +36,7 @@ export interface MetaElement {
foreign: boolean;
void: boolean;
transparent: boolean;
scriptSupporting: boolean;
/* attributes */
deprecatedAttributes: string[];
......@@ -130,6 +131,15 @@ as a child of a `<span>` element (phrasing) it only allows new phrasing content.
For custom elements it can be useful to set this if the content category isn't
flow.
### `scriptSupporting`
Elements whose primary purpose is to support scripting should set this flag to `true`.
Some elements will generally only allow a very narrow set of children (such as `<ul>` only allowing `<li>`) but usually also allows [script-supporting elements][whatwg-scriptsupporting].
In HTML5 both the `<script>` and `<template>` tags are considered script-supporting but javascript frameworks and web-components may include additional tags.
[whatwg-scriptsupporting]: https://html.spec.whatwg.org/multipage/dom.html#script-supporting-elements-2
## Permitted content
### `attributes`
......
......@@ -263,7 +263,7 @@
"dl": {
"flow": true,
"deprecatedAttributes": ["compact"],
"permittedContent": ["dt", "dd", "div", "script", "template"]
"permittedContent": ["@script", "dt", "dd", "div"]
},
"dt": {
......@@ -712,7 +712,7 @@
"type": ["a", "A", "i", "I", "1"]
},
"deprecatedAttributes": ["compact"],
"permittedContent": ["li", "script", "template"]
"permittedContent": ["@script", "li"]
},
"optgroup": {
......@@ -720,7 +720,7 @@
"attributes": {
"disabled": []
},
"permittedContent": ["option", "script", "template"]
"permittedContent": ["@script", "option"]
},
"option": {
......@@ -782,7 +782,7 @@
"flow": true,
"phrasing": true,
"embedded": true,
"permittedContent": ["source", "img", "script", "template"],
"permittedContent": ["@script", "source", "img"],
"permittedOrder": ["source", "img"]
},
......@@ -851,6 +851,7 @@
"metadata": true,
"flow": true,
"phrasing": true,
"scriptSupporting": true,
"attributes": {
"async": [],
"crossorigin": ["", "anonymous", "use-credentials"],
......@@ -880,13 +881,12 @@
"size": ["/\\d+/"]
},
"permittedContent": [
"@script",
"datasrc",
"datafld",
"dataformatas",
"option",
"optgroup",
"script",
"template"
"optgroup"
]
},
......@@ -969,11 +969,10 @@
"width"
],
"permittedContent": [
"@script",
"caption?",
"colgroup",
"script",
"tbody",
"template",
"tfoot?",
"thead?",
"tr"
......@@ -990,7 +989,7 @@
"charoff",
"valign"
],
"permittedContent": ["tr", "script", "template"]
"permittedContent": ["@script", "tr"]
},
"td": {
......@@ -1019,7 +1018,8 @@
"template": {
"metadata": true,
"flow": true,
"phrasing": true
"phrasing": true,
"scriptSupporting": true
},
"textarea": {
......@@ -1052,7 +1052,7 @@
"charoff",
"valign"
],
"permittedContent": ["tr", "script", "template"]
"permittedContent": ["@script", "tr"]
},
"th": {
......@@ -1091,7 +1091,7 @@
"charoff",
"valign"
],
"permittedContent": ["tr", "script", "template"]
"permittedContent": ["@script", "tr"]
},
"time": {
......@@ -1115,7 +1115,7 @@
"charoff",
"valign"
],
"permittedContent": ["td", "th", "script", "template"]
"permittedContent": ["@script", "td", "th"]
},
"track": {
......@@ -1135,7 +1135,7 @@
"ul": {
"flow": true,
"deprecatedAttributes": ["compact", "type"],
"permittedContent": ["li", "script", "template"]
"permittedContent": ["@script", "li"]
},
"var": {
......
......@@ -20,6 +20,7 @@
"void": { "type": "boolean" },
"transparent": { "type": "boolean" },
"implicitClosed": { "type": "array", "contains": { "type": "string" } },
"scriptSupporting": { "type": "boolean" },
"deprecatedAttributes": {
"type": "array",
......
......@@ -641,6 +641,7 @@ function mockEntry(stub = {}): MetaData {
deprecated: false,
void: false,
transparent: false,
scriptSupporting: false,
},
stub
);
......
......@@ -30,6 +30,7 @@ export interface MetaData {
void: boolean;
transparent: boolean;
implicitClosed?: string[];
scriptSupporting: boolean;
/* attribute */
deprecatedAttributes?: string[];
......
......@@ -321,6 +321,7 @@ function mockEntry(stub = {}): MetaData {
deprecated: false,
void: false,
transparent: false,
scriptSupporting: false,
},
stub
);
......
......@@ -589,6 +589,7 @@ function mockEntry(stub = {}): MetaData {
deprecated: false,
void: false,
transparent: false,
scriptSupporting: false,
},
stub
);
......
......@@ -235,6 +235,7 @@ export class Validator {
* @param {HtmlElement} node - The node to test against
* @param {string} category - Name of category with '@' prefix or tag name.
*/
// eslint-disable-next-line complexity
private static validatePermittedCategory(
node: HtmlElement,
category: string
......@@ -265,6 +266,8 @@ export class Validator {
return node.meta.embedded as boolean;
case "@interactive":
return node.meta.interactive as boolean;
case "@script":
return node.meta.scriptSupporting;
default:
throw new Error(`Invalid content category "${category}"`);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment