@markuplint/rules 3.0.0-alpha.0 → 3.0.0-alpha.1
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 +1 -1
- package/lib/attr-check.js +1 -1
- package/lib/attr-duplication/index.js +1 -1
- package/lib/attr-value-quotes/index.js +1 -1
- package/lib/case-sensitive-attr-name/index.js +3 -3
- package/lib/case-sensitive-tag-name/index.js +3 -3
- package/lib/class-naming/index.js +1 -1
- package/lib/create-message.d.ts +1 -1
- package/lib/create-message.js +5 -5
- package/lib/deprecated-element/index.js +2 -2
- package/lib/doctype/index.d.ts +1 -1
- package/lib/doctype/index.js +1 -1
- package/lib/end-tag/index.js +1 -1
- package/lib/helpers.d.ts +7 -2
- package/lib/helpers.js +17 -11
- package/lib/index.d.ts +2 -6
- package/lib/ineffective-attr/index.js +1 -1
- package/lib/invalid-attr/index.js +3 -3
- package/lib/landmark-roles/index.js +1 -1
- package/lib/no-boolean-attr-value/index.js +1 -1
- package/lib/no-default-value/index.js +1 -1
- package/lib/no-hard-code-id/index.js +1 -1
- package/lib/no-use-event-handler-attr/index.js +2 -2
- package/lib/permitted-contents/choice.d.ts +3 -0
- package/lib/permitted-contents/choice.js +37 -0
- package/lib/permitted-contents/complex-branch.d.ts +13 -0
- package/lib/permitted-contents/complex-branch.js +27 -0
- package/lib/permitted-contents/content-model.d.ts +2 -0
- package/lib/permitted-contents/content-model.js +49 -0
- package/lib/permitted-contents/count-pattern.d.ts +13 -0
- package/lib/permitted-contents/count-pattern.js +155 -0
- package/lib/permitted-contents/debug.d.ts +2 -0
- package/lib/permitted-contents/debug.js +5 -0
- package/lib/permitted-contents/index.d.ts +1 -7
- package/lib/permitted-contents/index.js +75 -245
- package/lib/permitted-contents/matches-selector.d.ts +3 -0
- package/lib/permitted-contents/matches-selector.js +185 -0
- package/lib/permitted-contents/order.d.ts +13 -0
- package/lib/permitted-contents/order.js +89 -0
- package/lib/permitted-contents/recursive-branch.d.ts +4 -0
- package/lib/permitted-contents/recursive-branch.js +43 -0
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
- package/lib/permitted-contents/represent-transparent-nodes.js +79 -0
- package/lib/permitted-contents/start.d.ts +12 -0
- package/lib/permitted-contents/start.js +71 -0
- package/lib/permitted-contents/transparent.d.ts +2 -0
- package/lib/permitted-contents/transparent.js +34 -0
- package/lib/permitted-contents/types.d.ts +45 -0
- package/lib/permitted-contents/types.js +2 -0
- package/lib/permitted-contents/utils.d.ts +32 -0
- package/lib/permitted-contents/utils.js +184 -0
- package/lib/require-accessible-name/index.js +5 -1
- package/lib/required-attr/index.js +1 -1
- package/lib/use-list/index.js +2 -2
- package/lib/wai-aria/checkings/implicit-role.js +2 -2
- package/lib/wai-aria/index.js +1 -1
- package/package.json +8 -7
- package/tsconfig.tsbuildinfo +1 -1
- 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.d.ts +0 -11
- package/lib/wai-aria/checkings/checking-required-owned-elements.js +0 -63
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchesSelector = void 0;
|
|
4
|
+
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
+
const debug_1 = require("./debug");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
function matchesSelector(query, node, specs, options, depth) {
|
|
8
|
+
const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
|
|
9
|
+
const { selector, hasText, hasCustom } = optCondition(query, specs);
|
|
10
|
+
if (node == null) {
|
|
11
|
+
if (hasText) {
|
|
12
|
+
nodeLog('<#text>.matches(%s) => ""', query);
|
|
13
|
+
return {
|
|
14
|
+
type: 'MATCHED_ZERO',
|
|
15
|
+
matched: node ? [node] : [],
|
|
16
|
+
unmatched: [],
|
|
17
|
+
zeroMatch: true,
|
|
18
|
+
query,
|
|
19
|
+
hint: {},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
type: 'MISSING_NODE',
|
|
24
|
+
matched: [],
|
|
25
|
+
unmatched: [],
|
|
26
|
+
zeroMatch: false,
|
|
27
|
+
query,
|
|
28
|
+
hint: {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (node.is(node.TEXT_NODE)) {
|
|
32
|
+
if (hasText) {
|
|
33
|
+
nodeLog('<#text>.matches(%s) => "%s"', query, node.raw.trim());
|
|
34
|
+
return {
|
|
35
|
+
type: 'MATCHED',
|
|
36
|
+
matched: [node],
|
|
37
|
+
unmatched: [],
|
|
38
|
+
zeroMatch: true,
|
|
39
|
+
query,
|
|
40
|
+
hint: {},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (node.isWhitespace()) {
|
|
44
|
+
nodeLog('<#text>.matches(%s) => WHITESPACE', query);
|
|
45
|
+
return {
|
|
46
|
+
type: 'MATCHED',
|
|
47
|
+
matched: [node],
|
|
48
|
+
unmatched: [],
|
|
49
|
+
zeroMatch: true,
|
|
50
|
+
query,
|
|
51
|
+
hint: {},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Disallows a text node
|
|
55
|
+
return {
|
|
56
|
+
type: 'UNEXPECTED_EXTRA_NODE',
|
|
57
|
+
matched: [],
|
|
58
|
+
unmatched: [node],
|
|
59
|
+
zeroMatch: false,
|
|
60
|
+
query,
|
|
61
|
+
hint: {},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
65
|
+
nodeLog('%s.matches(%s) => PBlock', node.raw, query);
|
|
66
|
+
return {
|
|
67
|
+
type: 'MATCHED',
|
|
68
|
+
matched: [node],
|
|
69
|
+
unmatched: [],
|
|
70
|
+
zeroMatch: !!hasText,
|
|
71
|
+
query,
|
|
72
|
+
hint: {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (node.is(node.ELEMENT_NODE)) {
|
|
76
|
+
if (node.elementType !== 'html' && hasCustom) {
|
|
77
|
+
nodeLog('%s.matches(%s) => CustomElement', node.raw, query);
|
|
78
|
+
return {
|
|
79
|
+
type: 'MATCHED',
|
|
80
|
+
matched: [node],
|
|
81
|
+
unmatched: [],
|
|
82
|
+
zeroMatch: !!hasText,
|
|
83
|
+
query,
|
|
84
|
+
hint: {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const result = (0, utils_1.matches)(selector, node, specs);
|
|
88
|
+
nodeLog('%s.matches(%s) => %s', node.raw, query, result.matched);
|
|
89
|
+
if (result.matched) {
|
|
90
|
+
return {
|
|
91
|
+
type: 'MATCHED',
|
|
92
|
+
matched: [node],
|
|
93
|
+
unmatched: [],
|
|
94
|
+
zeroMatch: !!hasText,
|
|
95
|
+
query,
|
|
96
|
+
hint: {},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (hasText) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY',
|
|
102
|
+
matched: [],
|
|
103
|
+
unmatched: [node],
|
|
104
|
+
zeroMatch: true,
|
|
105
|
+
query,
|
|
106
|
+
hint: {
|
|
107
|
+
not: result.not,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
type: 'UNMATCHED_SELECTORS',
|
|
113
|
+
matched: [],
|
|
114
|
+
unmatched: [node],
|
|
115
|
+
zeroMatch: false,
|
|
116
|
+
query,
|
|
117
|
+
hint: {
|
|
118
|
+
not: result.not,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
type: 'MATCHED',
|
|
124
|
+
matched: [node],
|
|
125
|
+
unmatched: [],
|
|
126
|
+
zeroMatch: !!hasText,
|
|
127
|
+
query,
|
|
128
|
+
hint: {},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
exports.matchesSelector = matchesSelector;
|
|
132
|
+
const conditionWithoutSpecs = {
|
|
133
|
+
'#custom': {
|
|
134
|
+
selector: '#custom',
|
|
135
|
+
hasCustom: true,
|
|
136
|
+
hasText: false,
|
|
137
|
+
},
|
|
138
|
+
'#text': {
|
|
139
|
+
selector: '#text',
|
|
140
|
+
hasCustom: false,
|
|
141
|
+
hasText: true,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
const optConditionSpecsBaseCaches = new Map();
|
|
145
|
+
function optCondition(query, specs) {
|
|
146
|
+
var _a;
|
|
147
|
+
const condWithoutSpecs = conditionWithoutSpecs[query];
|
|
148
|
+
if (condWithoutSpecs) {
|
|
149
|
+
return condWithoutSpecs;
|
|
150
|
+
}
|
|
151
|
+
const queryCaches = (_a = optConditionSpecsBaseCaches.get(specs)) !== null && _a !== void 0 ? _a : new Map();
|
|
152
|
+
const cached = queryCaches.get(query);
|
|
153
|
+
if (cached) {
|
|
154
|
+
return cached;
|
|
155
|
+
}
|
|
156
|
+
let hasCustom = false;
|
|
157
|
+
let hasText = false;
|
|
158
|
+
const selector = query.replace(/^(?::model\(([^)]+)\)|#([a-z-]+))(.*)$/, (_, $model, _model, $last) => {
|
|
159
|
+
const _selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${$model !== null && $model !== void 0 ? $model : _model}`, specs.def);
|
|
160
|
+
if (_selectors.length === 0) {
|
|
161
|
+
throw new Error(`${$model !== null && $model !== void 0 ? $model : _model} is empty`);
|
|
162
|
+
}
|
|
163
|
+
const selectors = [];
|
|
164
|
+
for (const selector of _selectors) {
|
|
165
|
+
if (selector === '#custom') {
|
|
166
|
+
hasCustom = true;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (selector === '#text') {
|
|
170
|
+
hasText = true;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
selectors.push(selector);
|
|
174
|
+
}
|
|
175
|
+
return `:is(${selectors.join(',')})${$last !== null && $last !== void 0 ? $last : ''}`;
|
|
176
|
+
});
|
|
177
|
+
const result = {
|
|
178
|
+
selector,
|
|
179
|
+
hasCustom,
|
|
180
|
+
hasText,
|
|
181
|
+
};
|
|
182
|
+
queryCaches.set(query, result);
|
|
183
|
+
optConditionSpecsBaseCaches.set(specs, queryCaches);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
+
import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
3
|
+
/**
|
|
4
|
+
* Check ordered array
|
|
5
|
+
*
|
|
6
|
+
* @param contents
|
|
7
|
+
* @param nodes
|
|
8
|
+
* @param specs
|
|
9
|
+
* @param options
|
|
10
|
+
* @param depth
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function order(contents: ReadonlyArray<PermittedContentPattern>, nodes: ReadonlyArray<ChildNode>, specs: Specs, options: Options, depth: number): Result;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.order = void 0;
|
|
4
|
+
const helpers_1 = require("../helpers");
|
|
5
|
+
const complex_branch_1 = require("./complex-branch");
|
|
6
|
+
const debug_1 = require("./debug");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* Check ordered array
|
|
10
|
+
*
|
|
11
|
+
* @param contents
|
|
12
|
+
* @param nodes
|
|
13
|
+
* @param specs
|
|
14
|
+
* @param options
|
|
15
|
+
* @param depth
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function order(contents, nodes, specs, options, depth) {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
const orderLog = debug_1.cmLog.extend(`order#${depth}`);
|
|
21
|
+
const btLog = debug_1.cmLog.extend(`backtrack#${depth}`);
|
|
22
|
+
const patterns = (0, helpers_1.deepCopy)(contents);
|
|
23
|
+
const collection = new utils_1.Collection(nodes);
|
|
24
|
+
orderLog('Starts: %s', collection);
|
|
25
|
+
let result = undefined;
|
|
26
|
+
let backtrackMode = false;
|
|
27
|
+
let afterBacktrack = false;
|
|
28
|
+
const unmatchedResults = [];
|
|
29
|
+
while (patterns.length) {
|
|
30
|
+
result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
|
|
31
|
+
collection.addMatched(result.matched);
|
|
32
|
+
orderLog('stack: %s', collection);
|
|
33
|
+
if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
|
|
34
|
+
unmatchedResults.push(result);
|
|
35
|
+
if (backtrackMode) {
|
|
36
|
+
collection.back();
|
|
37
|
+
btLog('🔙');
|
|
38
|
+
backtrackMode = false;
|
|
39
|
+
afterBacktrack = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
orderLog('conformed (%s): %s', result.type, collection.toString(true));
|
|
43
|
+
const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
|
|
44
|
+
if (!barelyMatchedResult) {
|
|
45
|
+
throw new Error('Unreachable code');
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
type: barelyMatchedResult.type,
|
|
49
|
+
matched: collection.matched,
|
|
50
|
+
unmatched: collection.unmatched,
|
|
51
|
+
zeroMatch: barelyMatchedResult.zeroMatch,
|
|
52
|
+
query: barelyMatchedResult.query,
|
|
53
|
+
hint: barelyMatchedResult.hint,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (afterBacktrack) {
|
|
57
|
+
collection.lock();
|
|
58
|
+
afterBacktrack = false;
|
|
59
|
+
}
|
|
60
|
+
if (result.zeroMatch) {
|
|
61
|
+
backtrackMode = true;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
backtrackMode = false;
|
|
65
|
+
}
|
|
66
|
+
patterns.shift();
|
|
67
|
+
}
|
|
68
|
+
if (collection.unmatched.length) {
|
|
69
|
+
orderLog('Conformed (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
|
|
70
|
+
return {
|
|
71
|
+
type: 'UNEXPECTED_EXTRA_NODE',
|
|
72
|
+
matched: collection.matched,
|
|
73
|
+
unmatched: collection.unmatched,
|
|
74
|
+
zeroMatch: false,
|
|
75
|
+
query: (_a = result === null || result === void 0 ? void 0 : result.query) !== null && _a !== void 0 ? _a : 'N/A',
|
|
76
|
+
hint: (_b = result === null || result === void 0 ? void 0 : result.hint) !== null && _b !== void 0 ? _b : {},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
orderLog('Conformed: %s', collection);
|
|
80
|
+
return {
|
|
81
|
+
type: collection.matched.length ? 'MATCHED' : 'MATCHED_ZERO',
|
|
82
|
+
matched: collection.matched,
|
|
83
|
+
unmatched: collection.unmatched,
|
|
84
|
+
zeroMatch: false,
|
|
85
|
+
query: (_c = result === null || result === void 0 ? void 0 : result.query) !== null && _c !== void 0 ? _c : 'N/A',
|
|
86
|
+
hint: (_d = result === null || result === void 0 ? void 0 : result.hint) !== null && _d !== void 0 ? _d : {},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
exports.order = order;
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
+
export declare function recursiveBranch(model: Model | PermittedContentPattern[], nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
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, nodes, specs, options, depth) {
|
|
8
|
+
if (!(0, utils_1.isModel)(model)) {
|
|
9
|
+
return (0, order_1.order)(model, nodes, specs, options, depth + 1);
|
|
10
|
+
}
|
|
11
|
+
if (typeof model === 'string') {
|
|
12
|
+
return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, options, depth);
|
|
13
|
+
}
|
|
14
|
+
const collection = new utils_1.Collection(nodes);
|
|
15
|
+
let lastUnmatched = null;
|
|
16
|
+
for (const query of model) {
|
|
17
|
+
const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, options, depth);
|
|
18
|
+
collection.addMatched(result.matched);
|
|
19
|
+
if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
|
|
20
|
+
return {
|
|
21
|
+
type: result.type,
|
|
22
|
+
matched: collection.matched,
|
|
23
|
+
unmatched: collection.unmatched,
|
|
24
|
+
zeroMatch: result.zeroMatch,
|
|
25
|
+
query: result.query,
|
|
26
|
+
hint: result.hint,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
lastUnmatched = {
|
|
30
|
+
type: result.type,
|
|
31
|
+
matched: collection.matched,
|
|
32
|
+
unmatched: collection.unmatched,
|
|
33
|
+
zeroMatch: result.zeroMatch,
|
|
34
|
+
query: result.query,
|
|
35
|
+
hint: result.hint,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!lastUnmatched) {
|
|
39
|
+
throw new Error('Unreachable code');
|
|
40
|
+
}
|
|
41
|
+
return lastUnmatched;
|
|
42
|
+
}
|
|
43
|
+
exports.recursiveBranch = recursiveBranch;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
+
export declare const transparentMode: Map<import("packages/@markuplint/ml-core/lib/ml-dom/node/child-node").MLChildNode<import("./types").TagRule[], Options>, true>;
|
|
3
|
+
export declare function representTransparentNodes(nodes: ChildNode[], specs: Specs, options: Options): {
|
|
4
|
+
nodes: ChildNode[];
|
|
5
|
+
errors: Result[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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(nodes, specs, options) {
|
|
9
|
+
var _a;
|
|
10
|
+
const result = [];
|
|
11
|
+
const errors = [];
|
|
12
|
+
const parent = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
13
|
+
if (parent) {
|
|
14
|
+
const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
|
|
15
|
+
errors.push(...parentErrors);
|
|
16
|
+
// if (!Array.isArray(parentRes)) {
|
|
17
|
+
// return parentRes;
|
|
18
|
+
// }
|
|
19
|
+
}
|
|
20
|
+
for (const node of nodes) {
|
|
21
|
+
if (!node.is(node.ELEMENT_NODE)) {
|
|
22
|
+
result.push(node);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const models = (0, ml_spec_1.getContentModel)(node, specs.specs);
|
|
26
|
+
if (models == null || typeof models === 'boolean') {
|
|
27
|
+
result.push(node);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const noTransparentModels = models.filter(m => !(0, utils_1.isTransparent)(m));
|
|
31
|
+
if (noTransparentModels.length === models.length) {
|
|
32
|
+
result.push(node);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
|
|
36
|
+
let unmatched;
|
|
37
|
+
if (noTransparentModels.length) {
|
|
38
|
+
const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
|
|
39
|
+
unmatched = result.unmatched;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
unmatched = collection.unmatched;
|
|
43
|
+
}
|
|
44
|
+
const transparent = models.find(m => (0, utils_1.isTransparent)(m));
|
|
45
|
+
if (!transparent || !(0, utils_1.isTransparent)(transparent)) {
|
|
46
|
+
throw new Error('Unreachable code');
|
|
47
|
+
}
|
|
48
|
+
for (const _child of unmatched) {
|
|
49
|
+
const child = _child;
|
|
50
|
+
if (exports.transparentMode.has(child)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
exports.transparentMode.set(child, true);
|
|
54
|
+
if (child.is(child.ELEMENT_NODE)) {
|
|
55
|
+
const transparentCondMatched = (0, utils_1.matches)(transparent.transparent, child, specs);
|
|
56
|
+
if (!transparentCondMatched.matched) {
|
|
57
|
+
errors.push({
|
|
58
|
+
type: 'TRANSPARENT_MODEL_DISALLOWS',
|
|
59
|
+
matched: [],
|
|
60
|
+
unmatched: [node],
|
|
61
|
+
zeroMatch: false,
|
|
62
|
+
query: transparent.transparent,
|
|
63
|
+
hint: {
|
|
64
|
+
not: transparentCondMatched.not,
|
|
65
|
+
transparent: node,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
result.push(child);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
nodes: result,
|
|
76
|
+
errors,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.representTransparentNodes = representTransparentNodes;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContentModelResult, Element, Options, Specs } from './types';
|
|
2
|
+
import type { ContentModel } from '@markuplint/ml-spec';
|
|
3
|
+
/**
|
|
4
|
+
* Check start
|
|
5
|
+
*
|
|
6
|
+
* @param contents
|
|
7
|
+
* @param el
|
|
8
|
+
* @param specs
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function start(contents: ContentModel['contents'], el: Element, specs: Specs, options: Options): ContentModelResult[];
|
|
@@ -0,0 +1,71 @@
|
|
|
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, el, specs, options) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (contents === false) {
|
|
19
|
+
if (el.childNodes.length) {
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
type: 'VOID_ELEMENT',
|
|
23
|
+
scope: el,
|
|
24
|
+
query: ':not(*)',
|
|
25
|
+
hint: {},
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
type: 'MATCHED',
|
|
32
|
+
scope: el,
|
|
33
|
+
query: '*',
|
|
34
|
+
hint: {},
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
if (contents === true) {
|
|
39
|
+
// Allows all elements
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
type: 'MATCHED',
|
|
43
|
+
scope: el,
|
|
44
|
+
query: '*',
|
|
45
|
+
hint: {},
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
const { nodes, errors } = (0, represent_transparent_nodes_1.representTransparentNodes)((0, utils_1.getChildNodesWithoutWhitespaces)(el), specs, options);
|
|
50
|
+
const result = (0, order_1.order)(contents, nodes, specs, options, 0);
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
type: result.type,
|
|
54
|
+
scope: result.type === 'MISSING_NODE_REQUIRED' || result.type === 'MISSING_NODE_ONE_OR_MORE'
|
|
55
|
+
? el
|
|
56
|
+
: (_a = result.unmatched[0]) !== null && _a !== void 0 ? _a : el,
|
|
57
|
+
query: result.query,
|
|
58
|
+
hint: result.hint,
|
|
59
|
+
},
|
|
60
|
+
...errors.map(error => {
|
|
61
|
+
var _a;
|
|
62
|
+
return ({
|
|
63
|
+
type: error.type,
|
|
64
|
+
scope: (_a = error.unmatched[0]) !== null && _a !== void 0 ? _a : el,
|
|
65
|
+
query: error.query,
|
|
66
|
+
hint: error.hint,
|
|
67
|
+
});
|
|
68
|
+
}),
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
exports.start = start;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transparent = void 0;
|
|
4
|
+
const count_pattern_1 = require("./count-pattern");
|
|
5
|
+
const debug_1 = require("./debug");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const transparentLog = debug_1.cmLog.extend('transparent');
|
|
8
|
+
function transparent(nodes, specs, options, depth) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (nodes.length === 0 || ((_a = nodes[0].parentElement) === null || _a === void 0 ? void 0 : _a.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
|
+
const collection = new utils_1.Collection(nodes);
|
|
23
|
+
const result = (0, count_pattern_1.countPattern)({ zeroOrMore: ':model(flow)' }, collection.unmatched, specs, options, depth);
|
|
24
|
+
collection.addMatched(result.matched);
|
|
25
|
+
return {
|
|
26
|
+
type: result.type,
|
|
27
|
+
matched: collection.matched,
|
|
28
|
+
unmatched: collection.unmatched,
|
|
29
|
+
zeroMatch: result.zeroMatch,
|
|
30
|
+
query: result.query,
|
|
31
|
+
hint: result.hint,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.transparent = transparent;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Element as _Element } from '@markuplint/ml-core';
|
|
2
|
+
import type { ContentModel, MLMLSpec } from '@markuplint/ml-spec';
|
|
3
|
+
export declare type Element = _Element<TagRule[], Options>;
|
|
4
|
+
export declare type ChildNode = Element['childNodes'][0];
|
|
5
|
+
export declare type Specs = {
|
|
6
|
+
cites: MLMLSpec['cites'];
|
|
7
|
+
def: MLMLSpec['def'];
|
|
8
|
+
specs: {
|
|
9
|
+
name: string;
|
|
10
|
+
contentModel: {
|
|
11
|
+
contents: MLMLSpec['specs'][0]['contentModel']['contents'];
|
|
12
|
+
};
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
export declare type ContentModelResult = {
|
|
16
|
+
type: MatchedReason | UnmatchedReason;
|
|
17
|
+
scope: ChildNode;
|
|
18
|
+
query: Result['query'];
|
|
19
|
+
hint: Result['hint'];
|
|
20
|
+
};
|
|
21
|
+
export declare type Result<T extends string = MatchedReason> = {
|
|
22
|
+
type: MatchedReason | UnmatchedReason | T;
|
|
23
|
+
matched: ChildNode[];
|
|
24
|
+
unmatched: ChildNode[];
|
|
25
|
+
zeroMatch: boolean;
|
|
26
|
+
query: string;
|
|
27
|
+
hint: {
|
|
28
|
+
max?: number;
|
|
29
|
+
not?: ChildNode;
|
|
30
|
+
transparent?: Element;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare type MatchedReason = 'MATCHED' | 'MATCHED_ZERO';
|
|
34
|
+
export declare type UnmatchedReason = 'VOID_ELEMENT' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
|
|
35
|
+
export declare type MissingNodeReason = 'MISSING_NODE_REQUIRED' | 'MISSING_NODE_ONE_OR_MORE';
|
|
36
|
+
export declare type TransparentModel = {
|
|
37
|
+
el: Element;
|
|
38
|
+
additionalCondition: string;
|
|
39
|
+
};
|
|
40
|
+
export declare type TagRule = {
|
|
41
|
+
tag: string;
|
|
42
|
+
} & ContentModel;
|
|
43
|
+
export declare type Options = {
|
|
44
|
+
ignoreHasMutableChildren: boolean;
|
|
45
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ChildNode, Element, Specs } from './types';
|
|
2
|
+
import type { PermittedContentPattern, PermittedContentChoice, PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentTransparent, PermittedContentZeroOrMore, Model } from '@markuplint/ml-spec';
|
|
3
|
+
export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
|
|
4
|
+
export declare function isModel(model: Model | PermittedContentPattern[]): model is Model;
|
|
5
|
+
export declare function matches(selector: string, node: ChildNode, specs: Specs): {
|
|
6
|
+
matched: boolean;
|
|
7
|
+
not?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
matched: boolean;
|
|
10
|
+
not: import("packages/@markuplint/ml-core/lib/ml-dom/node/child-node").MLChildNode<import("./types").TagRule[], import("./types").Options> | undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare function isRequire(content: PermittedContentPattern): content is PermittedContentRequire;
|
|
13
|
+
export declare function isOptional(content: PermittedContentPattern): content is PermittedContentOptional;
|
|
14
|
+
export declare function isOneOrMore(content: PermittedContentPattern): content is PermittedContentOneOrMore;
|
|
15
|
+
export declare function isZeroOrMore(content: PermittedContentPattern): content is PermittedContentZeroOrMore;
|
|
16
|
+
export declare function isChoice(content: PermittedContentPattern): content is PermittedContentChoice;
|
|
17
|
+
export declare function isTransparent(content: PermittedContentPattern): content is PermittedContentTransparent;
|
|
18
|
+
export declare class Collection {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(origin: readonly ChildNode[]);
|
|
21
|
+
get matched(): import("packages/@markuplint/ml-core/lib/ml-dom/node/child-node").MLChildNode<import("./types").TagRule[], import("./types").Options>[];
|
|
22
|
+
get matchedCount(): number;
|
|
23
|
+
get nodes(): import("packages/@markuplint/ml-core/lib/ml-dom/node/child-node").MLChildNode<import("./types").TagRule[], import("./types").Options>[];
|
|
24
|
+
get unmatched(): import("packages/@markuplint/ml-core/lib/ml-dom/node/child-node").MLChildNode<import("./types").TagRule[], import("./types").Options>[];
|
|
25
|
+
addMatched(nodes: ChildNode[]): boolean;
|
|
26
|
+
back(): void;
|
|
27
|
+
lock(): void;
|
|
28
|
+
max(max: number): void;
|
|
29
|
+
toString(highlightExtraNodes?: boolean): string;
|
|
30
|
+
}
|
|
31
|
+
export declare class UnsupportedError extends Error {
|
|
32
|
+
}
|