Commit 66d75a86 authored by David Sveningsson's avatar David Sveningsson

feat(meta): support @form category

parent e00e1ed3
......@@ -1816,7 +1816,7 @@ exports[`HTML elements <footer> valid markup 1`] = `Array []`;
exports[`HTML elements <form> invalid markup 1`] = `
Array [
Object {
"errorCount": 1,
"errorCount": 2,
"filePath": "test-files/elements/form-invalid.html",
"messages": Array [
Object {
......@@ -1829,11 +1829,26 @@ Array [
"severity": 2,
"size": 4,
},
Object {
"column": 3,
"context": undefined,
"line": 8,
"message": "Element <custom-form> is not permitted as descendant of <form>",
"offset": 129,
"ruleId": "element-permitted-content",
"severity": 2,
"size": 11,
},
],
"source": "<!-- should not allow nesting -->
<form>
<form></form>
</form>
<!-- should not allow nesting with custom elements -->
<form>
<custom-form></custom-form>
</form>
",
"warningCount": 0,
},
......
......@@ -334,7 +334,7 @@
},
"deprecatedAttributes": ["accept"],
"permittedContent": ["@flow"],
"permittedDescendants": [{ "exclude": ["form"] }]
"permittedDescendants": [{ "exclude": ["@form"] }]
},
"frame": {
......
......@@ -144,6 +144,15 @@ const tagNames = [
describe("HTML elements", () => {
const htmlvalidate = new HtmlValidate({
extends: ["htmlvalidate:recommended"],
elements: [
"html5",
{
"custom-form": {
flow: true,
form: true,
},
},
],
rules: {
/* allow any style of boolean attributes, some tests runs all of them */
"attribute-boolean-style": "off",
......
......@@ -152,6 +152,40 @@ describe("Meta validator", () => {
expect(Validator.validatePermitted(nil, rules)).toBeFalsy();
});
it("should validate @script", () => {
const table = new MetaTable();
table.loadFromObject({
nil: mockEntry({ void: true }),
scripting: mockEntry({
scriptSupporting: true,
void: true,
}),
});
const parser = new Parser(new ConfigMock(table));
const [script, nil] = parser.parseHtml(
"<scripting/><nil/>"
).root.childElements;
const rules = ["@script"];
expect(Validator.validatePermitted(script, rules)).toBeTruthy();
expect(Validator.validatePermitted(nil, rules)).toBeFalsy();
});
it("should validate @form", () => {
const table = new MetaTable();
table.loadFromObject({
nil: mockEntry({ void: true }),
form: mockEntry({
form: true,
void: true,
}),
});
const parser = new Parser(new ConfigMock(table));
const [form, nil] = parser.parseHtml("<form/><nil/>").root.childElements;
const rules = ["@form"];
expect(Validator.validatePermitted(form, rules)).toBeTruthy();
expect(Validator.validatePermitted(nil, rules)).toBeFalsy();
});
it("should validate multiple rules (OR)", () => {
const table = new MetaTable();
table.loadFromObject({
......
......@@ -268,6 +268,8 @@ export class Validator {
return node.meta.interactive as boolean;
case "@script":
return node.meta.scriptSupporting;
case "@form":
return node.meta.form;
default:
throw new Error(`Invalid content category "${category}"`);
}
......
......@@ -2,3 +2,8 @@
<form>
<form></form>
</form>
<!-- should not allow nesting with custom elements -->
<form>
<custom-form></custom-form>
</form>
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