@markuplint/rules 3.0.0-alpha.66 → 3.0.0-dev.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -44
- package/lib/attr-check.d.ts +22 -10
- package/lib/attr-check.js +32 -23
- package/lib/attr-duplication/index.d.ts +3 -1
- package/lib/attr-duplication/index.js +3 -2
- package/lib/attr-value-quotes/index.d.ts +5 -5
- package/lib/attr-value-quotes/index.js +1 -1
- package/lib/case-sensitive-attr-name/index.d.ts +2 -2
- package/lib/case-sensitive-attr-name/index.js +3 -3
- package/lib/case-sensitive-tag-name/index.d.ts +2 -2
- package/lib/case-sensitive-tag-name/index.js +3 -3
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/character-reference/index.js +1 -1
- package/lib/class-naming/index.d.ts +2 -2
- package/lib/class-naming/index.js +3 -5
- package/lib/create-message.d.ts +13 -2
- package/lib/create-message.js +9 -8
- package/lib/debug.d.ts +1 -1
- package/lib/debug.js +1 -1
- package/lib/deprecated-attr/index.d.ts +3 -1
- package/lib/deprecated-element/index.d.ts +3 -1
- package/lib/deprecated-element/index.js +4 -4
- package/lib/disallowed-element/index.d.ts +1 -1
- package/lib/doctype/index.d.ts +3 -3
- package/lib/doctype/index.js +2 -2
- package/lib/end-tag/index.d.ts +1 -1
- package/lib/end-tag/index.js +3 -18
- package/lib/helpers.d.ts +38 -47
- package/lib/helpers.js +42 -93
- package/lib/id-duplication/index.d.ts +3 -1
- package/lib/index.d.ts +242 -62
- package/lib/index.js +10 -1
- package/lib/ineffective-attr/index.d.ts +3 -1
- package/lib/ineffective-attr/index.js +3 -6
- package/lib/invalid-attr/index.d.ts +40 -12
- package/lib/invalid-attr/index.js +159 -28
- package/lib/label-has-control/index.d.ts +4 -0
- package/lib/label-has-control/index.js +28 -0
- package/lib/landmark-roles/index.d.ts +6 -6
- package/lib/landmark-roles/index.js +10 -6
- package/lib/no-boolean-attr-value/index.d.ts +3 -1
- package/lib/no-boolean-attr-value/index.js +1 -1
- package/lib/no-default-value/index.d.ts +3 -1
- package/lib/no-default-value/index.js +1 -1
- package/lib/no-empty-palpable-content/index.d.ts +6 -0
- package/lib/no-empty-palpable-content/index.js +42 -0
- package/lib/no-hard-code-id/index.d.ts +3 -1
- package/lib/no-hard-code-id/index.js +1 -1
- package/lib/no-refer-to-non-existent-id/index.d.ts +9 -4
- package/lib/no-refer-to-non-existent-id/index.js +65 -5
- package/lib/no-use-event-handler-attr/index.d.ts +3 -3
- package/lib/no-use-event-handler-attr/index.js +6 -6
- package/lib/permitted-contents/choice.d.ts +10 -0
- package/lib/permitted-contents/choice.js +72 -0
- package/lib/permitted-contents/complex-branch.d.ts +20 -0
- package/lib/permitted-contents/complex-branch.js +29 -0
- package/lib/permitted-contents/content-model.d.ts +2 -0
- package/lib/permitted-contents/content-model.js +53 -0
- package/lib/permitted-contents/count-pattern.d.ts +29 -0
- package/lib/permitted-contents/count-pattern.js +162 -0
- package/lib/permitted-contents/debug.browser.d.ts +30 -0
- package/lib/permitted-contents/debug.browser.js +14 -0
- package/lib/permitted-contents/debug.d.ts +3 -0
- package/lib/permitted-contents/debug.js +13 -0
- package/lib/permitted-contents/index.d.ts +2 -8
- package/lib/permitted-contents/index.js +76 -249
- package/lib/permitted-contents/matches-selector.d.ts +8 -0
- package/lib/permitted-contents/matches-selector.js +187 -0
- package/lib/permitted-contents/order.d.ts +20 -0
- package/lib/permitted-contents/order.js +99 -0
- package/lib/permitted-contents/recursive-branch.d.ts +11 -0
- package/lib/permitted-contents/recursive-branch.js +45 -0
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +10 -0
- package/lib/permitted-contents/represent-transparent-nodes.js +78 -0
- package/lib/permitted-contents/start.d.ts +18 -0
- package/lib/permitted-contents/start.js +73 -0
- package/lib/permitted-contents/transparent.d.ts +2 -0
- package/lib/permitted-contents/transparent.js +31 -0
- package/lib/permitted-contents/types.d.ts +52 -0
- package/lib/permitted-contents/types.js +2 -0
- package/lib/permitted-contents/utils.d.ts +100 -0
- package/lib/permitted-contents/utils.js +302 -0
- package/lib/placeholder-label-option/index.d.ts +2 -0
- package/lib/placeholder-label-option/index.js +88 -0
- package/lib/require-accessible-name/index.d.ts +3 -3
- package/lib/require-accessible-name/index.js +12 -4
- package/lib/require-datetime/index.d.ts +6 -0
- package/lib/require-datetime/index.js +34 -0
- package/lib/require-datetime/types.d.ts +10 -0
- package/lib/require-datetime/types.js +2 -0
- package/lib/require-datetime/utils.d.ts +11 -0
- package/lib/require-datetime/utils.js +137 -0
- package/lib/required-attr/index.d.ts +5 -5
- package/lib/required-attr/index.js +20 -17
- package/lib/required-element/index.d.ts +3 -3
- package/lib/required-element/index.js +3 -2
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +4 -3
- package/lib/use-list/index.d.ts +4 -4
- package/lib/use-list/index.js +9 -7
- package/lib/wai-aria/checkings/_.d.ts +15 -0
- package/lib/wai-aria/checkings/_.js +27 -0
- package/lib/wai-aria/checkings/abstract-role.js +1 -1
- package/lib/wai-aria/checkings/default-value.d.ts +7 -3
- package/lib/wai-aria/checkings/deprecated-props.d.ts +8 -4
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +8 -4
- package/lib/wai-aria/checkings/disallowed-prop.js +27 -3
- package/lib/wai-aria/checkings/implicit-props.d.ts +8 -4
- package/lib/wai-aria/checkings/implicit-props.js +3 -2
- package/lib/wai-aria/checkings/implicit-role.js +2 -2
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
- package/lib/wai-aria/checkings/interaction-in-hidden.js +49 -0
- package/lib/wai-aria/checkings/no-global-prop.d.ts +7 -3
- package/lib/wai-aria/checkings/{non-existant-role.d.ts → non-existent-role.d.ts} +1 -1
- package/lib/wai-aria/checkings/{non-existant-role.js → non-existent-role.js} +4 -4
- package/lib/wai-aria/checkings/permitted-roles.js +1 -1
- package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
- package/lib/wai-aria/checkings/presentational-children.js +62 -0
- package/lib/wai-aria/checkings/{checking-required-owned-elements.d.ts → required-owned-elements.d.ts} +7 -3
- package/lib/wai-aria/checkings/required-owned-elements.js +103 -0
- package/lib/wai-aria/checkings/required-prop copy.d.ts +15 -0
- package/lib/wai-aria/checkings/required-prop copy.js +27 -0
- package/lib/wai-aria/checkings/required-prop.d.ts +12 -6
- package/lib/wai-aria/checkings/unadopted-explicit-roles.d.ts +15 -0
- package/lib/wai-aria/checkings/unadopted-explicit-roles.js +17 -0
- package/lib/wai-aria/checkings/value.d.ts +19 -4
- package/lib/wai-aria/checkings/value.js +77 -5
- package/lib/wai-aria/index.d.ts +1 -1
- package/lib/wai-aria/index.js +27 -16
- package/lib/wai-aria/types.d.ts +11 -9
- package/lib/xxx/index.d.ts +2 -0
- package/lib/xxx/index.js +32 -0
- package/package.json +18 -12
- package/schema.json +12 -0
- package/test/attr-check.spec.js +77 -0
- package/test/attr-duplication/index.spec.js +159 -0
- package/test/attr-value-quotes/index.spec.js +133 -0
- package/test/case-sensitive-attr-name/index.spec.js +65 -0
- package/test/case-sensitive-tag-name/index.spec.js +80 -0
- package/test/character-reference/index.spec.js +57 -0
- package/test/class-naming/index.spec.js +470 -0
- package/test/create-message.spec.js +497 -0
- package/test/deprecated-attr/index.spec.js +48 -0
- package/test/deprecated-element/index.spec.js +48 -0
- package/test/disallowed-element/index.spec.js +90 -0
- package/test/doctype/index.spec.js +50 -0
- package/test/end-tag/index.spec.js +162 -0
- package/test/id-duplication/index.spec.js +47 -0
- package/test/ineffective-attr/index.spec.js +31 -0
- package/test/invalid-attr/index.spec.js +1632 -0
- package/test/label-has-control/index.spec.js +29 -0
- package/test/landmark-roles/index.spec.js +187 -0
- package/test/no-boolean-attr-value/index.spec.js +41 -0
- package/test/no-default-value/index.spec.js +74 -0
- package/test/no-empty-palpable-content/index.spec.js +115 -0
- package/test/no-hard-code-id/index.spec.js +100 -0
- package/test/no-refer-to-non-existent-id/index.spec.js +254 -0
- package/test/no-use-event-handler-attr/index.spec.js +57 -0
- package/test/permitted-contents/choice.spec.js +174 -0
- package/test/permitted-contents/count-pattern.spec.js +308 -0
- package/test/permitted-contents/index.spec.js +1371 -0
- package/test/permitted-contents/matches-selector.spec.js +59 -0
- package/test/permitted-contents/order.spec.js +351 -0
- package/test/permitted-contents/recursive-branch.spec.js +41 -0
- package/test/permitted-contents/represent-transparent-nodes.spec.js +24 -0
- package/test/permitted-contents/start.spec.js +67 -0
- package/test/placeholder-label-option/index.spec.js +113 -0
- package/test/require-accessible-name/index.spec.js +446 -0
- package/test/require-datetime/index.spec.js +54 -0
- package/test/require-datetime/utils.spec.js +52 -0
- package/test/required-attr/index.spec.js +414 -0
- package/test/required-element/index.spec.js +188 -0
- package/test/required-h1/index.spec.js +69 -0
- package/test/use-list/index.spec.js +109 -0
- package/test/wai-aria/checkings/value.spec.js +33 -0
- package/test/wai-aria/index.spec.js +1173 -0
- package/lib/__foo/index.d.ts +0 -2
- package/lib/__foo/index.js +0 -46
- package/lib/attr-equal-space-after/index.d.ts +0 -3
- package/lib/attr-equal-space-after/index.js +0 -90
- package/lib/attr-equal-space-before/index.d.ts +0 -3
- package/lib/attr-equal-space-before/index.js +0 -90
- package/lib/attr-spacing/index.d.ts +0 -6
- package/lib/attr-spacing/index.js +0 -100
- package/lib/helper/aria/get-aria.d.ts +0 -7
- package/lib/helper/aria/get-aria.js +0 -53
- package/lib/helper/aria/get-computed-role.d.ts +0 -10
- package/lib/helper/aria/get-computed-role.js +0 -24
- package/lib/helper/aria/get-implicit-role.d.ts +0 -7
- package/lib/helper/aria/get-implicit-role.js +0 -12
- package/lib/helper/aria/get-permitted-roles.d.ts +0 -14
- package/lib/helper/aria/get-permitted-roles.js +0 -26
- package/lib/helper/aria/resolve-version.d.ts +0 -2
- package/lib/helper/aria/resolve-version.js +0 -21
- package/lib/helper/spec/aria-spec.d.ts +0 -5
- package/lib/helper/spec/aria-spec.js +0 -12
- package/lib/helper/spec/get-role-spec.d.ts +0 -11
- package/lib/helper/spec/get-role-spec.js +0 -39
- package/lib/helper/spec/html-spec.d.ts +0 -2
- package/lib/helper/spec/html-spec.js +0 -14
- package/lib/indentation/index.d.ts +0 -7
- package/lib/indentation/index.js +0 -208
- package/lib/permitted-contents/array.combination.d.ts +0 -1
- package/lib/permitted-contents/array.combination.js +0 -33
- package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
- package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -230
- package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
- package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
- package/lib/wai-aria/checkings/checking-required-owned-elements.js +0 -63
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SelectorResult } from './matches-selector';
|
|
2
|
+
import type { ChildNode, Options, Specs } from './types';
|
|
3
|
+
import type { PermittedContentPattern, Model } from '@markuplint/ml-spec';
|
|
4
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
5
|
+
export declare function recursiveBranch(
|
|
6
|
+
model: ReadonlyDeep<Model | PermittedContentPattern[]>,
|
|
7
|
+
nodes: readonly ChildNode[],
|
|
8
|
+
specs: Specs,
|
|
9
|
+
options: Options,
|
|
10
|
+
depth: number,
|
|
11
|
+
): SelectorResult;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recursiveBranch = void 0;
|
|
4
|
+
const matches_selector_1 = require("./matches-selector");
|
|
5
|
+
const order_1 = require("./order");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
function recursiveBranch(model,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
|
+
nodes, specs, options, depth) {
|
|
10
|
+
if (!(0, utils_1.isModel)(model)) {
|
|
11
|
+
return (0, order_1.order)(model, nodes, specs, options, depth + 1);
|
|
12
|
+
}
|
|
13
|
+
if (typeof model === 'string') {
|
|
14
|
+
return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, depth);
|
|
15
|
+
}
|
|
16
|
+
const collection = new utils_1.Collection(nodes);
|
|
17
|
+
let lastUnmatched = null;
|
|
18
|
+
for (const query of model) {
|
|
19
|
+
const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, depth);
|
|
20
|
+
collection.addMatched(result.matched);
|
|
21
|
+
if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
|
|
22
|
+
return {
|
|
23
|
+
type: result.type,
|
|
24
|
+
matched: collection.matched,
|
|
25
|
+
unmatched: collection.unmatched,
|
|
26
|
+
zeroMatch: result.zeroMatch,
|
|
27
|
+
query: result.query,
|
|
28
|
+
hint: result.hint,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
lastUnmatched = {
|
|
32
|
+
type: result.type,
|
|
33
|
+
matched: collection.matched,
|
|
34
|
+
unmatched: collection.unmatched,
|
|
35
|
+
zeroMatch: result.zeroMatch,
|
|
36
|
+
query: result.query,
|
|
37
|
+
hint: result.hint,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!lastUnmatched) {
|
|
41
|
+
throw new Error('Unreachable code');
|
|
42
|
+
}
|
|
43
|
+
return lastUnmatched;
|
|
44
|
+
}
|
|
45
|
+
exports.recursiveBranch = recursiveBranch;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
+
export declare const transparentMode: Map<ChildNode, true>;
|
|
3
|
+
export declare function representTransparentNodes(
|
|
4
|
+
nodes: ChildNode[],
|
|
5
|
+
specs: Specs,
|
|
6
|
+
options: Options,
|
|
7
|
+
): {
|
|
8
|
+
nodes: ChildNode[];
|
|
9
|
+
errors: Result[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.representTransparentNodes = exports.transparentMode = void 0;
|
|
4
|
+
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
+
const order_1 = require("./order");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
exports.transparentMode = new Map();
|
|
8
|
+
function representTransparentNodes(
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
|
+
nodes, specs, options) {
|
|
11
|
+
var _a;
|
|
12
|
+
const result = [];
|
|
13
|
+
const errors = [];
|
|
14
|
+
const parent = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
15
|
+
if (parent) {
|
|
16
|
+
const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
|
|
17
|
+
errors.push(...parentErrors);
|
|
18
|
+
}
|
|
19
|
+
for (const node of nodes) {
|
|
20
|
+
if (!node.is(node.ELEMENT_NODE)) {
|
|
21
|
+
result.push(node);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const models = (0, ml_spec_1.getContentModel)(node, specs.specs);
|
|
25
|
+
if (models == null || typeof models === 'boolean') {
|
|
26
|
+
result.push(node);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const noTransparentModels = models.filter(m => !(0, utils_1.isTransparent)(m));
|
|
30
|
+
if (noTransparentModels.length === models.length) {
|
|
31
|
+
result.push(node);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
|
|
35
|
+
let unmatched;
|
|
36
|
+
if (noTransparentModels.length > 0) {
|
|
37
|
+
const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
|
|
38
|
+
unmatched = result.unmatched;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
unmatched = collection.unmatched;
|
|
42
|
+
}
|
|
43
|
+
const transparent = models.find(m => (0, utils_1.isTransparent)(m));
|
|
44
|
+
if (!transparent || !(0, utils_1.isTransparent)(transparent)) {
|
|
45
|
+
throw new Error('Unreachable code');
|
|
46
|
+
}
|
|
47
|
+
for (const _child of unmatched) {
|
|
48
|
+
const child = _child;
|
|
49
|
+
if (exports.transparentMode.has(child)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
exports.transparentMode.set(child, true);
|
|
53
|
+
if (child.is(child.ELEMENT_NODE)) {
|
|
54
|
+
const transparentCondMatched = (0, utils_1.matches)(transparent.transparent, child, specs);
|
|
55
|
+
if (!transparentCondMatched.matched) {
|
|
56
|
+
errors.push({
|
|
57
|
+
type: 'TRANSPARENT_MODEL_DISALLOWS',
|
|
58
|
+
matched: [],
|
|
59
|
+
unmatched: [node],
|
|
60
|
+
zeroMatch: false,
|
|
61
|
+
query: transparent.transparent,
|
|
62
|
+
hint: {
|
|
63
|
+
not: transparentCondMatched.not,
|
|
64
|
+
transparent: node,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
result.push(child);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
nodes: result,
|
|
75
|
+
errors,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.representTransparentNodes = representTransparentNodes;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContentModelResult, Element, Options, Specs } from './types';
|
|
2
|
+
import type { ContentModel } from '@markuplint/ml-spec';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
/**
|
|
5
|
+
* Check start
|
|
6
|
+
*
|
|
7
|
+
* @param contents
|
|
8
|
+
* @param el
|
|
9
|
+
* @param specs
|
|
10
|
+
* @param options
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function start(
|
|
14
|
+
contents: ReadonlyDeep<ContentModel['contents']>,
|
|
15
|
+
el: Element,
|
|
16
|
+
specs: Specs,
|
|
17
|
+
options: Options,
|
|
18
|
+
): ContentModelResult[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.start = void 0;
|
|
4
|
+
const order_1 = require("./order");
|
|
5
|
+
const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
/**
|
|
8
|
+
* Check start
|
|
9
|
+
*
|
|
10
|
+
* @param contents
|
|
11
|
+
* @param el
|
|
12
|
+
* @param specs
|
|
13
|
+
* @param options
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function start(contents,
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
18
|
+
el, specs, options) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (contents === false) {
|
|
21
|
+
if (el.childNodes.length > 0) {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
type: 'NOTHING',
|
|
25
|
+
scope: el,
|
|
26
|
+
query: ':not(*)',
|
|
27
|
+
hint: {},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
type: 'MATCHED',
|
|
34
|
+
scope: el,
|
|
35
|
+
query: '*',
|
|
36
|
+
hint: {},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
if (contents === true) {
|
|
41
|
+
// Allows all elements
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
type: 'MATCHED',
|
|
45
|
+
scope: el,
|
|
46
|
+
query: '*',
|
|
47
|
+
hint: {},
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
const { nodes, errors } = (0, represent_transparent_nodes_1.representTransparentNodes)((0, utils_1.getChildNodesWithoutWhitespaces)(el), specs, options);
|
|
52
|
+
const result = (0, order_1.order)(contents, nodes, specs, options, 0);
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
type: result.type,
|
|
56
|
+
scope: result.type === 'MISSING_NODE_REQUIRED' || result.type === 'MISSING_NODE_ONE_OR_MORE'
|
|
57
|
+
? el
|
|
58
|
+
: (_a = result.unmatched[0]) !== null && _a !== void 0 ? _a : el,
|
|
59
|
+
query: result.query,
|
|
60
|
+
hint: result.hint,
|
|
61
|
+
},
|
|
62
|
+
...errors.map(error => {
|
|
63
|
+
var _a;
|
|
64
|
+
return ({
|
|
65
|
+
type: error.type,
|
|
66
|
+
scope: (_a = error.unmatched[0]) !== null && _a !== void 0 ? _a : el,
|
|
67
|
+
query: error.query,
|
|
68
|
+
hint: error.hint,
|
|
69
|
+
});
|
|
70
|
+
}),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
exports.start = start;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transparent = void 0;
|
|
4
|
+
const debug_1 = require("./debug");
|
|
5
|
+
const transparentLog = debug_1.cmLog.extend('transparent');
|
|
6
|
+
function transparent(
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
nodes) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
|
|
11
|
+
transparentLog('Skipped');
|
|
12
|
+
return {
|
|
13
|
+
type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
|
|
14
|
+
matched: nodes.slice(),
|
|
15
|
+
unmatched: [],
|
|
16
|
+
zeroMatch: nodes.length === 0,
|
|
17
|
+
query: 'transparent',
|
|
18
|
+
hint: {},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
transparentLog('Transparent model element is component root');
|
|
22
|
+
return {
|
|
23
|
+
type: 'MATCHED',
|
|
24
|
+
matched: nodes.slice(),
|
|
25
|
+
unmatched: [],
|
|
26
|
+
zeroMatch: false,
|
|
27
|
+
query: 'transparent',
|
|
28
|
+
hint: {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.transparent = transparent;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Element as _Element, ChildNode as _ChildNode } from '@markuplint/ml-core';
|
|
2
|
+
import type { ContentModel, MLMLSpec } from '@markuplint/ml-spec';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
export type Element = _Element<TagRule[], Options>;
|
|
5
|
+
export type ChildNode = _ChildNode<TagRule[], Options>;
|
|
6
|
+
export type Specs = {
|
|
7
|
+
readonly cites: MLMLSpec['cites'];
|
|
8
|
+
readonly def: MLMLSpec['def'];
|
|
9
|
+
readonly specs: readonly {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly contentModel: {
|
|
12
|
+
readonly contents: MLMLSpec['specs'][0]['contentModel']['contents'];
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
export type ContentModelResult = {
|
|
17
|
+
type: MatchedReason | UnmatchedReason;
|
|
18
|
+
scope: ChildNode;
|
|
19
|
+
query: Result['query'];
|
|
20
|
+
hint: Result['hint'];
|
|
21
|
+
};
|
|
22
|
+
export type Result<T extends string = MatchedReason> = {
|
|
23
|
+
type: MatchedReason | UnmatchedReason | T;
|
|
24
|
+
matched: ChildNode[];
|
|
25
|
+
unmatched: ChildNode[];
|
|
26
|
+
zeroMatch: boolean;
|
|
27
|
+
query: string;
|
|
28
|
+
hint: Hints;
|
|
29
|
+
};
|
|
30
|
+
export type Hints = {
|
|
31
|
+
max?: number;
|
|
32
|
+
not?: ChildNode;
|
|
33
|
+
transparent?: Element;
|
|
34
|
+
missing?: {
|
|
35
|
+
barelyMatchedElements?: number;
|
|
36
|
+
need?: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type MatchedReason = 'MATCHED' | 'MATCHED_ZERO';
|
|
40
|
+
export type UnmatchedReason = 'NOTHING' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
|
|
41
|
+
export type MissingNodeReason = 'MISSING_NODE_REQUIRED' | 'MISSING_NODE_ONE_OR_MORE';
|
|
42
|
+
export type RepeatSign = '' | '?' | '+' | '*' | `{${number},${number}}`;
|
|
43
|
+
export type TransparentModel = {
|
|
44
|
+
el: Element;
|
|
45
|
+
additionalCondition: string;
|
|
46
|
+
};
|
|
47
|
+
export type TagRule = {
|
|
48
|
+
readonly tag: string;
|
|
49
|
+
} & ReadonlyDeep<ContentModel>;
|
|
50
|
+
export type Options = {
|
|
51
|
+
readonly ignoreHasMutableChildren: boolean;
|
|
52
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types';
|
|
2
|
+
import type {
|
|
3
|
+
PermittedContentPattern,
|
|
4
|
+
PermittedContentChoice,
|
|
5
|
+
PermittedContentOneOrMore,
|
|
6
|
+
PermittedContentOptional,
|
|
7
|
+
PermittedContentRequire,
|
|
8
|
+
PermittedContentTransparent,
|
|
9
|
+
PermittedContentZeroOrMore,
|
|
10
|
+
Model,
|
|
11
|
+
} from '@markuplint/ml-spec';
|
|
12
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
13
|
+
export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
|
|
14
|
+
export declare function isModel(model: ReadonlyDeep<Model | PermittedContentPattern[]>): model is ReadonlyDeep<Model>;
|
|
15
|
+
export declare function matches(
|
|
16
|
+
selector: string,
|
|
17
|
+
node: ChildNode,
|
|
18
|
+
specs: Specs,
|
|
19
|
+
):
|
|
20
|
+
| {
|
|
21
|
+
matched: boolean;
|
|
22
|
+
not?: undefined;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
matched: boolean;
|
|
26
|
+
not: ChildNode | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare function isRequire(
|
|
29
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
30
|
+
): content is ReadonlyDeep<PermittedContentRequire>;
|
|
31
|
+
export declare function isOptional(
|
|
32
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
33
|
+
): content is ReadonlyDeep<PermittedContentOptional>;
|
|
34
|
+
export declare function isOneOrMore(
|
|
35
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
36
|
+
): content is ReadonlyDeep<PermittedContentOneOrMore>;
|
|
37
|
+
export declare function isZeroOrMore(
|
|
38
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
39
|
+
): content is ReadonlyDeep<PermittedContentZeroOrMore>;
|
|
40
|
+
export declare function isChoice(
|
|
41
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
42
|
+
): content is ReadonlyDeep<PermittedContentChoice>;
|
|
43
|
+
export declare function isTransparent(
|
|
44
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
45
|
+
): content is ReadonlyDeep<PermittedContentTransparent>;
|
|
46
|
+
export declare function normalizeModel(
|
|
47
|
+
pattern:
|
|
48
|
+
| ReadonlyDeep<PermittedContentRequire>
|
|
49
|
+
| ReadonlyDeep<PermittedContentOptional>
|
|
50
|
+
| ReadonlyDeep<PermittedContentOneOrMore>
|
|
51
|
+
| ReadonlyDeep<PermittedContentZeroOrMore>,
|
|
52
|
+
): {
|
|
53
|
+
model: ReadonlyDeep<PermittedContentPattern[] | Model>;
|
|
54
|
+
min: number;
|
|
55
|
+
max: number;
|
|
56
|
+
repeat: RepeatSign;
|
|
57
|
+
missingType: MissingNodeReason | undefined;
|
|
58
|
+
};
|
|
59
|
+
export declare function mergeHints(
|
|
60
|
+
a: Readonly<Hints>,
|
|
61
|
+
b: Readonly<Hints>,
|
|
62
|
+
): Partial<{
|
|
63
|
+
missing:
|
|
64
|
+
| Partial<{
|
|
65
|
+
barelyMatchedElements?: number | undefined;
|
|
66
|
+
need?: string | undefined;
|
|
67
|
+
}>
|
|
68
|
+
| undefined;
|
|
69
|
+
max?: number | undefined;
|
|
70
|
+
not?:
|
|
71
|
+
| import('packages/@markuplint/ml-core/lib').DocumentType<
|
|
72
|
+
import('./types').TagRule[],
|
|
73
|
+
import('./types').Options
|
|
74
|
+
>
|
|
75
|
+
| import('packages/@markuplint/ml-core/lib/ml-dom/node/character-data').MLCharacterData<
|
|
76
|
+
import('./types').TagRule[],
|
|
77
|
+
import('./types').Options,
|
|
78
|
+
import('packages/@markuplint/ml-ast/lib').MLASTAbstractNode
|
|
79
|
+
>
|
|
80
|
+
| import('packages/@markuplint/ml-core/lib').Element<import('./types').TagRule[], import('./types').Options>
|
|
81
|
+
| import('packages/@markuplint/ml-core/lib').Block<import('./types').TagRule[], import('./types').Options>
|
|
82
|
+
| undefined;
|
|
83
|
+
transparent?: Element | undefined;
|
|
84
|
+
}>;
|
|
85
|
+
export declare function cleanObject<T extends Object>(object: T): Partial<T>;
|
|
86
|
+
export declare class Collection {
|
|
87
|
+
#private;
|
|
88
|
+
constructor(origin: readonly ChildNode[]);
|
|
89
|
+
get matched(): ChildNode[];
|
|
90
|
+
get matchedCount(): number;
|
|
91
|
+
get nodes(): ChildNode[];
|
|
92
|
+
get unmatched(): ChildNode[];
|
|
93
|
+
addMatched(nodes: ChildNode[]): boolean;
|
|
94
|
+
back(): void;
|
|
95
|
+
lock(): void;
|
|
96
|
+
max(max: number): void;
|
|
97
|
+
toString(highlightExtraNodes?: boolean): string;
|
|
98
|
+
}
|
|
99
|
+
export declare class UnsupportedError extends Error {}
|
|
100
|
+
export declare function modelLog(model: ReadonlyDeep<Model | PermittedContentPattern[]>, repeat: RepeatSign): string;
|