@markuplint/ml-core 4.0.0-alpha.1 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/configs.browser.js +10 -6
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -3
- package/lib/ml-core.d.ts +2 -2
- package/lib/ml-core.js +44 -20
- package/lib/ml-dom/helper/accname.js +3 -3
- package/lib/ml-dom/helper/create-node.d.ts +2 -2
- package/lib/ml-dom/helper/create-node.js +32 -7
- package/lib/ml-dom/helper/debug.js +11 -15
- package/lib/ml-dom/helper/{getIndent.js → get-indent.js} +14 -4
- package/lib/ml-dom/helper/walkers.js +1 -1
- package/lib/ml-dom/manipulations/child-node-methods.js +1 -1
- package/lib/ml-dom/manipulations/get-children.js +1 -1
- package/lib/ml-dom/node/attr.d.ts +18 -0
- package/lib/ml-dom/node/attr.js +80 -32
- package/lib/ml-dom/node/block.js +1 -3
- package/lib/ml-dom/node/character-data.d.ts +2 -2
- package/lib/ml-dom/node/character-data.js +1 -1
- package/lib/ml-dom/node/child-node.d.ts +2 -2
- package/lib/ml-dom/node/document-fragment.d.ts +2 -2
- package/lib/ml-dom/node/document-fragment.js +1 -1
- package/lib/ml-dom/node/document-type.js +1 -3
- package/lib/ml-dom/node/document.d.ts +7 -5
- package/lib/ml-dom/node/document.js +105 -39
- package/lib/ml-dom/node/dom-token-list.js +15 -5
- package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
- package/lib/ml-dom/node/element-close-tag.js +39 -0
- package/lib/ml-dom/node/element.d.ts +51 -6
- package/lib/ml-dom/node/element.js +139 -62
- package/lib/ml-dom/node/named-node-map.js +1 -1
- package/lib/ml-dom/node/node-list.js +2 -2
- package/lib/ml-dom/node/node-store.d.ts +3 -3
- package/lib/ml-dom/node/node-store.js +7 -3
- package/lib/ml-dom/node/node.d.ts +2 -2
- package/lib/ml-dom/node/node.js +31 -13
- package/lib/ml-dom/node/parent-node.d.ts +2 -2
- package/lib/ml-dom/node/parent-node.js +13 -3
- package/lib/ml-dom/node/rule-mapper.js +17 -7
- package/lib/ml-dom/node/text.js +3 -3
- package/lib/ml-dom/node/types.d.ts +23 -3
- package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -1
- package/lib/ml-dom/node/unexpected-call-error.js +1 -1
- package/lib/ml-dom/token/token.d.ts +3 -3
- package/lib/ml-dom/token/token.js +16 -6
- package/lib/ml-rule/ml-rule-context.js +6 -2
- package/lib/ml-rule/ml-rule.d.ts +1 -1
- package/lib/ml-rule/ml-rule.js +12 -2
- package/lib/ml-rule/types.d.ts +3 -0
- package/lib/ruleset/index.d.ts +1 -1
- package/lib/ruleset/index.js +1 -1
- package/lib/test/index.d.ts +6 -4
- package/lib/test/index.js +7 -3
- package/lib/types.d.ts +3 -3
- package/lib/utils/get-location-from-chars.js +3 -3
- package/package.json +13 -14
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -37
- /package/lib/ml-dom/helper/{getIndent.d.ts → get-indent.d.ts} +0 -0
package/LICENSE
CHANGED
package/lib/configs.browser.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export async function getPreset(name) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch(
|
|
3
|
+
() =>
|
|
4
|
+
// eslint-disable-next-line unicorn/error-message
|
|
5
|
+
new Error(),
|
|
6
|
+
);
|
|
7
|
+
if (res instanceof Error) {
|
|
8
|
+
throw new ReferenceError(`Preset markuplint:${name} is not found`);
|
|
9
|
+
}
|
|
10
|
+
const json = await res.json();
|
|
11
|
+
return json;
|
|
8
12
|
}
|
package/lib/convert-ruleset.d.ts
CHANGED
package/lib/convert-ruleset.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { RuleInfo, RuleConfig, RuleConfigValue } from '@markuplint/ml-config';
|
|
2
2
|
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
3
|
-
export {
|
|
3
|
+
export { Ruleset } from './ruleset/index.js';
|
|
4
4
|
export { enableDebug } from './debug.js';
|
|
5
|
-
export { getIndent } from './ml-dom/helper/
|
|
6
|
-
export * from './configs.js';
|
|
5
|
+
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
7
6
|
export * from './convert-ruleset.js';
|
|
8
7
|
export * from './ml-core.js';
|
|
9
8
|
export * from './ml-dom/index.js';
|
|
@@ -12,3 +11,4 @@ export * from './plugin/index.js';
|
|
|
12
11
|
export * from './test/index.js';
|
|
13
12
|
export * from './types.js';
|
|
14
13
|
export * from './utils/index.js';
|
|
14
|
+
export { AccessibilityProperties } from './ml-dom/node/types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
2
|
-
export {
|
|
2
|
+
export { Ruleset } from './ruleset/index.js';
|
|
3
3
|
export { enableDebug } from './debug.js';
|
|
4
|
-
export { getIndent } from './ml-dom/helper/
|
|
5
|
-
export * from './configs.js';
|
|
4
|
+
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
6
5
|
export * from './convert-ruleset.js';
|
|
7
6
|
export * from './ml-core.js';
|
|
8
7
|
export * from './ml-dom/index.js';
|
package/lib/ml-core.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export type MLCoreParams = {
|
|
|
9
9
|
} & MLFabric;
|
|
10
10
|
export declare class MLCore {
|
|
11
11
|
#private;
|
|
12
|
-
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }: MLCoreParams);
|
|
12
|
+
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }: MLCoreParams);
|
|
13
13
|
get document(): ParserError | Document<RuleConfigValue, PlainData>;
|
|
14
14
|
setCode(sourceCode: string): void;
|
|
15
|
-
update({ parser, ruleset, rules, locale, schemas, parserOptions }: Partial<MLFabric>): void;
|
|
15
|
+
update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }: Partial<MLFabric>): void;
|
|
16
16
|
verify(fix?: boolean): Promise<Violation[]>;
|
|
17
17
|
private _createDocument;
|
|
18
18
|
private _parse;
|
package/lib/ml-core.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _MLCore_ast, _MLCore_document, _MLCore_filename, _MLCore_locale, _MLCore_parser, _MLCore_parserOptions, _MLCore_pretenders, _MLCore_rules, _MLCore_ruleset, _MLCore_schemas, _MLCore_sourceCode, _MLCore_configErrors;
|
|
3
13
|
import { ParserError } from '@markuplint/parser-utils';
|
|
4
14
|
import { log, enableDebug } from './debug.js';
|
|
5
15
|
import { Document } from './ml-dom/index.js';
|
|
6
16
|
const resultLog = log.extend('result');
|
|
7
17
|
export class MLCore {
|
|
8
|
-
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }) {
|
|
18
|
+
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }) {
|
|
9
19
|
_MLCore_ast.set(this, null);
|
|
10
20
|
_MLCore_document.set(this, void 0);
|
|
11
21
|
_MLCore_filename.set(this, void 0);
|
|
@@ -17,6 +27,7 @@ export class MLCore {
|
|
|
17
27
|
_MLCore_ruleset.set(this, void 0);
|
|
18
28
|
_MLCore_schemas.set(this, void 0);
|
|
19
29
|
_MLCore_sourceCode.set(this, void 0);
|
|
30
|
+
_MLCore_configErrors.set(this, void 0);
|
|
20
31
|
if (debug) {
|
|
21
32
|
enableDebug();
|
|
22
33
|
}
|
|
@@ -31,8 +42,9 @@ export class MLCore {
|
|
|
31
42
|
__classPrivateFieldSet(this, _MLCore_locale, locale, "f");
|
|
32
43
|
__classPrivateFieldSet(this, _MLCore_schemas, schemas, "f");
|
|
33
44
|
__classPrivateFieldSet(this, _MLCore_filename, filename, "f");
|
|
34
|
-
__classPrivateFieldSet(this, _MLCore_rules, rules
|
|
35
|
-
__classPrivateFieldSet(this, _MLCore_pretenders, pretenders
|
|
45
|
+
__classPrivateFieldSet(this, _MLCore_rules, [...rules], "f");
|
|
46
|
+
__classPrivateFieldSet(this, _MLCore_pretenders, [...pretenders], "f");
|
|
47
|
+
__classPrivateFieldSet(this, _MLCore_configErrors, [...(configErrors ?? [])], "f");
|
|
36
48
|
this._parse();
|
|
37
49
|
this._createDocument();
|
|
38
50
|
}
|
|
@@ -44,7 +56,7 @@ export class MLCore {
|
|
|
44
56
|
this._parse();
|
|
45
57
|
this._createDocument();
|
|
46
58
|
}
|
|
47
|
-
update({ parser, ruleset, rules, locale, schemas, parserOptions }) {
|
|
59
|
+
update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }) {
|
|
48
60
|
__classPrivateFieldSet(this, _MLCore_parser, parser ?? __classPrivateFieldGet(this, _MLCore_parser, "f"), "f");
|
|
49
61
|
__classPrivateFieldSet(this, _MLCore_ruleset, {
|
|
50
62
|
rules: ruleset?.rules ?? __classPrivateFieldGet(this, _MLCore_ruleset, "f").rules,
|
|
@@ -54,6 +66,7 @@ export class MLCore {
|
|
|
54
66
|
__classPrivateFieldSet(this, _MLCore_rules, rules?.slice() ?? __classPrivateFieldGet(this, _MLCore_rules, "f"), "f");
|
|
55
67
|
__classPrivateFieldSet(this, _MLCore_locale, locale ?? __classPrivateFieldGet(this, _MLCore_locale, "f"), "f");
|
|
56
68
|
__classPrivateFieldSet(this, _MLCore_schemas, schemas ?? __classPrivateFieldGet(this, _MLCore_schemas, "f"), "f");
|
|
69
|
+
__classPrivateFieldSet(this, _MLCore_configErrors, [...(configErrors ?? [])], "f");
|
|
57
70
|
if (parserOptions &&
|
|
58
71
|
(parserOptions.ignoreFrontMatter !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").ignoreFrontMatter ||
|
|
59
72
|
parserOptions.authoredElementName !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").authoredElementName)) {
|
|
@@ -76,17 +89,27 @@ export class MLCore {
|
|
|
76
89
|
log('verify: error %o', __classPrivateFieldGet(this, _MLCore_document, "f").message);
|
|
77
90
|
return violations;
|
|
78
91
|
}
|
|
92
|
+
for (const error of __classPrivateFieldGet(this, _MLCore_configErrors, "f")) {
|
|
93
|
+
violations.push({
|
|
94
|
+
ruleId: 'config-error',
|
|
95
|
+
severity: 'warning',
|
|
96
|
+
message: error.message,
|
|
97
|
+
col: 1,
|
|
98
|
+
line: 1,
|
|
99
|
+
raw: '',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
79
102
|
for (const rule of __classPrivateFieldGet(this, _MLCore_rules, "f")) {
|
|
80
103
|
const ruleInfo = rule.getRuleInfo(__classPrivateFieldGet(this, _MLCore_ruleset, "f"), rule.name);
|
|
81
104
|
if (ruleInfo.disabled && ruleInfo.nodeRules.length === 0 && ruleInfo.childNodeRules.length === 0) {
|
|
82
105
|
continue;
|
|
83
106
|
}
|
|
84
107
|
log('%s Rule: verify', rule.name);
|
|
85
|
-
const results = await rule.verify(__classPrivateFieldGet(this, _MLCore_document, "f"), __classPrivateFieldGet(this, _MLCore_locale, "f"), fix).catch(
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
108
|
+
const results = await rule.verify(__classPrivateFieldGet(this, _MLCore_document, "f"), __classPrivateFieldGet(this, _MLCore_locale, "f"), fix).catch(error => {
|
|
109
|
+
if (error instanceof ParserError) {
|
|
110
|
+
return error;
|
|
88
111
|
}
|
|
89
|
-
throw
|
|
112
|
+
throw error;
|
|
90
113
|
});
|
|
91
114
|
if (results instanceof ParserError) {
|
|
92
115
|
log('%s Rule: verify error %o', rule.name, results.message);
|
|
@@ -105,6 +128,7 @@ export class MLCore {
|
|
|
105
128
|
log('%s Rule: verify end', rule.name);
|
|
106
129
|
}
|
|
107
130
|
if (resultLog.enabled) {
|
|
131
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
108
132
|
const { e, w, i } = violations.reduce((c, v) => {
|
|
109
133
|
if (v.severity === 'error')
|
|
110
134
|
c.e += 1;
|
|
@@ -133,12 +157,12 @@ export class MLCore {
|
|
|
133
157
|
pretenders: __classPrivateFieldGet(this, _MLCore_pretenders, "f"),
|
|
134
158
|
}), "f");
|
|
135
159
|
}
|
|
136
|
-
catch (
|
|
137
|
-
if (
|
|
138
|
-
__classPrivateFieldSet(this, _MLCore_document,
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof ParserError) {
|
|
162
|
+
__classPrivateFieldSet(this, _MLCore_document, error, "f");
|
|
139
163
|
}
|
|
140
164
|
else {
|
|
141
|
-
throw
|
|
165
|
+
throw error;
|
|
142
166
|
}
|
|
143
167
|
}
|
|
144
168
|
}
|
|
@@ -146,16 +170,16 @@ export class MLCore {
|
|
|
146
170
|
try {
|
|
147
171
|
__classPrivateFieldSet(this, _MLCore_ast, __classPrivateFieldGet(this, _MLCore_parser, "f").parse(__classPrivateFieldGet(this, _MLCore_sourceCode, "f"), __classPrivateFieldGet(this, _MLCore_parserOptions, "f")), "f");
|
|
148
172
|
}
|
|
149
|
-
catch (
|
|
150
|
-
log('Caught the parse error: %O',
|
|
173
|
+
catch (error) {
|
|
174
|
+
log('Caught the parse error: %O', error);
|
|
151
175
|
__classPrivateFieldSet(this, _MLCore_ast, null, "f");
|
|
152
|
-
if (
|
|
153
|
-
__classPrivateFieldSet(this, _MLCore_document,
|
|
176
|
+
if (error instanceof ParserError) {
|
|
177
|
+
__classPrivateFieldSet(this, _MLCore_document, error, "f");
|
|
154
178
|
}
|
|
155
179
|
else {
|
|
156
|
-
throw
|
|
180
|
+
throw error;
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
184
|
}
|
|
161
|
-
_MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap();
|
|
185
|
+
_MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap(), _MLCore_configErrors = new WeakMap();
|
|
@@ -16,7 +16,7 @@ el, version) {
|
|
|
16
16
|
return '';
|
|
17
17
|
}
|
|
18
18
|
if (isFromContent(el, version)) {
|
|
19
|
-
return
|
|
19
|
+
return [...el.childNodes]
|
|
20
20
|
.map(child => {
|
|
21
21
|
if (child.is(child.ELEMENT_NODE)) {
|
|
22
22
|
return getAccname(child, version);
|
|
@@ -37,9 +37,9 @@ el) {
|
|
|
37
37
|
const name = get(el);
|
|
38
38
|
return name;
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
40
|
+
catch (error) {
|
|
41
41
|
accnameLog('Raw: %s', el.raw);
|
|
42
|
-
accnameLog('Error: %O',
|
|
42
|
+
accnameLog('Error: %O', error);
|
|
43
43
|
return '';
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MLDocument } from '../node/document.js';
|
|
2
2
|
import type { MappedNode } from '../node/types.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
4
4
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
-
export declare function createNode<N extends
|
|
5
|
+
export declare function createNode<N extends MLASTNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N, document: MLDocument<T, O>): MappedNode<N, T, O>;
|
|
@@ -6,22 +6,47 @@ import { MLText } from '../node/text.js';
|
|
|
6
6
|
export function createNode(astNode,
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
8
|
document) {
|
|
9
|
-
|
|
10
|
-
switch (_astNode.type) {
|
|
9
|
+
switch (astNode.type) {
|
|
11
10
|
case 'doctype': {
|
|
12
|
-
return new MLDocumentType(
|
|
11
|
+
return new MLDocumentType(astNode, document);
|
|
13
12
|
}
|
|
14
13
|
case 'starttag': {
|
|
15
|
-
return new MLElement(
|
|
14
|
+
return new MLElement(astNode, document);
|
|
16
15
|
}
|
|
17
16
|
case 'psblock': {
|
|
18
|
-
return new MLBlock(
|
|
17
|
+
return new MLBlock(astNode, document);
|
|
19
18
|
}
|
|
20
19
|
case 'comment': {
|
|
21
|
-
return new MLComment(
|
|
20
|
+
return new MLComment(astNode, document);
|
|
22
21
|
}
|
|
23
22
|
case 'text': {
|
|
24
|
-
return new MLText(
|
|
23
|
+
return new MLText(astNode, document);
|
|
24
|
+
}
|
|
25
|
+
case 'invalid': {
|
|
26
|
+
switch (astNode.kind) {
|
|
27
|
+
case 'starttag': {
|
|
28
|
+
return new MLElement({
|
|
29
|
+
...astNode,
|
|
30
|
+
type: 'starttag',
|
|
31
|
+
nodeName: 'x-invalid',
|
|
32
|
+
namespace: 'http://www.w3.org/1999/xhtml',
|
|
33
|
+
elementType: 'web-component',
|
|
34
|
+
attributes: [],
|
|
35
|
+
childNodes: [],
|
|
36
|
+
pairNode: null,
|
|
37
|
+
tagOpenChar: '',
|
|
38
|
+
tagCloseChar: '',
|
|
39
|
+
isGhost: false,
|
|
40
|
+
}, document);
|
|
41
|
+
}
|
|
42
|
+
default: {
|
|
43
|
+
return new MLText({
|
|
44
|
+
...astNode,
|
|
45
|
+
type: 'text',
|
|
46
|
+
nodeName: '#text',
|
|
47
|
+
}, document);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
25
50
|
}
|
|
26
51
|
}
|
|
27
52
|
throw new TypeError(`Invalid AST node types "${astNode.type}"`);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export function nodeListToDebugMaps(
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
3
3
|
nodeList, withAttr = false) {
|
|
4
|
-
return nodeList
|
|
5
|
-
.map(n => {
|
|
4
|
+
return nodeList.flatMap(n => {
|
|
6
5
|
const r = [];
|
|
7
6
|
if (n.is(n.ELEMENT_NODE) && n.isOmitted) {
|
|
8
7
|
r.push(`[N/A]>[N/A](N/A)${n.nodeName}: ${visibleWhiteSpace(n.raw)}`);
|
|
@@ -10,10 +9,9 @@ nodeList, withAttr = false) {
|
|
|
10
9
|
}
|
|
11
10
|
r.push(tokenDebug(n));
|
|
12
11
|
if (n.is(n.ELEMENT_NODE)) {
|
|
13
|
-
r.push(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
r.push(` isForeignElement: ${!!n.isForeignElement}`);
|
|
12
|
+
r.push(
|
|
13
|
+
//
|
|
14
|
+
` namespaceURI: ${!!n.namespaceURI}`, ` elementType: ${n.elementType}`, ` isInFragmentDocument: ${n.isInFragmentDocument()}`, ` isForeignElement: ${!!n.isForeignElement}`);
|
|
17
15
|
if (withAttr) {
|
|
18
16
|
r.push(...attributesToDebugMaps(n.attributes)
|
|
19
17
|
.flat()
|
|
@@ -21,14 +19,12 @@ nodeList, withAttr = false) {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
return r;
|
|
24
|
-
})
|
|
25
|
-
.flat();
|
|
22
|
+
});
|
|
26
23
|
}
|
|
27
24
|
function attributesToDebugMaps(
|
|
28
25
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
29
26
|
attributes) {
|
|
30
|
-
return attributes
|
|
31
|
-
.map(n => {
|
|
27
|
+
return attributes.flatMap(n => {
|
|
32
28
|
const r = [
|
|
33
29
|
tokenDebug({
|
|
34
30
|
name: n.name,
|
|
@@ -66,19 +62,19 @@ attributes) {
|
|
|
66
62
|
r.push(` ${tokenDebug(n.endQuote, 'eQ')}`);
|
|
67
63
|
}
|
|
68
64
|
if (n.spacesBeforeName) {
|
|
69
|
-
r.push(
|
|
70
|
-
|
|
65
|
+
r.push(
|
|
66
|
+
//
|
|
67
|
+
` isDirective: ${!!n.isDirective}`, ` isDynamicValue: ${!!n.isDynamicValue}`);
|
|
71
68
|
}
|
|
72
69
|
if (n.candidate) {
|
|
73
70
|
r.push(` candidate: ${visibleWhiteSpace(n.candidate)}`);
|
|
74
71
|
}
|
|
75
72
|
return r;
|
|
76
|
-
})
|
|
77
|
-
.flat();
|
|
73
|
+
});
|
|
78
74
|
}
|
|
79
75
|
function tokenDebug(n, type = '') {
|
|
80
76
|
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${n.nodeName ?? n.potentialName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
|
|
81
77
|
}
|
|
82
78
|
function visibleWhiteSpace(chars) {
|
|
83
|
-
return chars.
|
|
79
|
+
return chars.replaceAll('\n', '⏎').replaceAll('\t', '→').replaceAll(/\s/g, '␣');
|
|
84
80
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
1
12
|
var _MLDOMIndentation_fixed, _MLDOMIndentation_node, _MLDOMIndentation_parent;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
/**
|
|
4
14
|
*
|
|
5
15
|
* @deprecated
|
|
@@ -16,7 +26,7 @@ node) {
|
|
|
16
26
|
if (node.isRawTextElementContent()) {
|
|
17
27
|
return null;
|
|
18
28
|
}
|
|
19
|
-
const matched = node.raw.match(/^(\
|
|
29
|
+
const matched = node.raw.match(/^([\t\v\f\r \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*\n\s*)\S+/);
|
|
20
30
|
if (matched) {
|
|
21
31
|
const spaces = matched[1];
|
|
22
32
|
if (spaces) {
|
|
@@ -36,8 +46,8 @@ node) {
|
|
|
36
46
|
// One or more newlines and zero or more spaces or tabs.
|
|
37
47
|
// Or, If textNode is first token and that is filled spaces, tabs and newlines only.
|
|
38
48
|
const matched = isFirstToken(prevToken)
|
|
39
|
-
? prevToken.raw.match(/^(?:[
|
|
40
|
-
: prevToken.raw.match(/\r?\n([
|
|
49
|
+
? prevToken.raw.match(/^(?:[\t ]*\r?\n)*([\t ]*)$/)
|
|
50
|
+
: prevToken.raw.match(/\r?\n([\t ]*)$/);
|
|
41
51
|
// console.log({ [`${this}`]: matched, _: prevToken.raw, f: prevToken._isFirstToken() });
|
|
42
52
|
if (matched) {
|
|
43
53
|
// Spaces will include empty string.
|
|
@@ -3,7 +3,7 @@ export function syncWalk(
|
|
|
3
3
|
nodeList, walker) {
|
|
4
4
|
for (const node of nodeList) {
|
|
5
5
|
if (node.is(node.ELEMENT_NODE) || node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
6
|
-
syncWalk(
|
|
6
|
+
syncWalk([...node.childNodes], walker);
|
|
7
7
|
}
|
|
8
8
|
walker(node);
|
|
9
9
|
}
|
|
@@ -2,7 +2,7 @@ import { toHTMLCollection } from '../node/node-list.js';
|
|
|
2
2
|
export function getChildren(
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
4
4
|
node) {
|
|
5
|
-
return toHTMLCollection(
|
|
5
|
+
return toHTMLCollection([...node.childNodes].filter((child) => {
|
|
6
6
|
return child.nodeType === child.ELEMENT_NODE;
|
|
7
7
|
}));
|
|
8
8
|
}
|
|
@@ -91,8 +91,26 @@ export declare class MLAttr<T extends RuleConfigValue, O extends PlainData = und
|
|
|
91
91
|
* @see https://dom.spec.whatwg.org/#dom-attr-value
|
|
92
92
|
*/
|
|
93
93
|
get value(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Fixes the attribute value.
|
|
96
|
+
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`.
|
|
97
|
+
*
|
|
98
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
99
|
+
*
|
|
100
|
+
* @param raw - The raw attribute value.
|
|
101
|
+
*/
|
|
102
|
+
fix(raw: string): void;
|
|
94
103
|
/**
|
|
95
104
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
96
105
|
*/
|
|
97
106
|
toNormalizeString(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Returns a string representation of the attribute.
|
|
109
|
+
*
|
|
110
|
+
* @implements DOM API: `Attr`
|
|
111
|
+
*
|
|
112
|
+
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name.
|
|
113
|
+
* @returns The string representation of the attribute.
|
|
114
|
+
*/
|
|
115
|
+
toString(fixed?: boolean): string;
|
|
98
116
|
}
|
package/lib/ml-dom/node/attr.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
1
12
|
var _MLAttr_localName, _MLAttr_namespaceURI, _MLAttr_potentialName, _MLAttr_potentialValue;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { resolveNamespace } from '@markuplint/ml-spec';
|
|
4
14
|
import { MLToken } from '../token/token.js';
|
|
5
15
|
import { MLDomTokenList } from './dom-token-list.js';
|
|
6
16
|
import { MLNode } from './node.js';
|
|
7
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
8
18
|
export class MLAttr extends MLNode {
|
|
9
|
-
constructor(
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
|
-
astToken,
|
|
19
|
+
constructor(astToken,
|
|
12
20
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
13
21
|
ownElement) {
|
|
14
22
|
super(astToken, ownElement.ownerMLDocument);
|
|
@@ -31,32 +39,35 @@ export class MLAttr extends MLNode {
|
|
|
31
39
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
32
40
|
*/
|
|
33
41
|
this.valueType = 'string';
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this
|
|
37
|
-
this.
|
|
38
|
-
this
|
|
39
|
-
this
|
|
40
|
-
this
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
this.candidate = this._astToken.candidate;
|
|
46
|
-
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f");
|
|
47
|
-
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.value.raw ?? '', "f");
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
this.valueType = this._astToken.valueType;
|
|
51
|
-
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
52
|
-
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f");
|
|
53
|
-
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue, "f");
|
|
42
|
+
this.ownerElement = ownElement;
|
|
43
|
+
if (this._astToken.type === 'spread') {
|
|
44
|
+
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ownElement.namespaceURI, "f");
|
|
45
|
+
this.valueType = 'code';
|
|
46
|
+
__classPrivateFieldSet(this, _MLAttr_localName, '#spread', "f");
|
|
47
|
+
__classPrivateFieldSet(this, _MLAttr_potentialName, '#spread', "f");
|
|
48
|
+
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.raw, "f");
|
|
49
|
+
this.isDirective = true;
|
|
50
|
+
this.isDynamicValue = true;
|
|
51
|
+
this.isDuplicatable = true;
|
|
52
|
+
return;
|
|
54
53
|
}
|
|
54
|
+
this.spacesBeforeName = new MLToken(this._astToken.spacesBeforeName);
|
|
55
|
+
this.nameNode = new MLToken(this._astToken.name);
|
|
56
|
+
this.spacesBeforeEqual = new MLToken(this._astToken.spacesBeforeEqual);
|
|
57
|
+
this.equal = new MLToken(this._astToken.equal);
|
|
58
|
+
this.spacesAfterEqual = new MLToken(this._astToken.spacesAfterEqual);
|
|
59
|
+
this.startQuote = new MLToken(this._astToken.startQuote);
|
|
60
|
+
this.valueNode = new MLToken(this._astToken.value);
|
|
61
|
+
this.endQuote = new MLToken(this._astToken.endQuote);
|
|
62
|
+
this.isDynamicValue = this._astToken.isDynamicValue;
|
|
63
|
+
this.isDirective = this._astToken.isDirective;
|
|
64
|
+
this.candidate = this._astToken.candidate;
|
|
65
|
+
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f");
|
|
66
|
+
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue ?? this.valueNode?.raw ?? '', "f");
|
|
67
|
+
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
55
68
|
const ns = resolveNamespace(__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI);
|
|
56
69
|
__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f");
|
|
57
70
|
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f");
|
|
58
|
-
this.ownerElement = ownElement;
|
|
59
|
-
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
60
71
|
}
|
|
61
72
|
/**
|
|
62
73
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -139,18 +150,55 @@ export class MLAttr extends MLNode {
|
|
|
139
150
|
get value() {
|
|
140
151
|
return __classPrivateFieldGet(this, _MLAttr_potentialValue, "f");
|
|
141
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Fixes the attribute value.
|
|
155
|
+
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`.
|
|
156
|
+
*
|
|
157
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
158
|
+
*
|
|
159
|
+
* @param raw - The raw attribute value.
|
|
160
|
+
*/
|
|
161
|
+
fix(raw) {
|
|
162
|
+
if (this.localName === '#spread') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// `valueNode` is not null when it is no spread.
|
|
166
|
+
this.valueNode?.fix(raw);
|
|
167
|
+
}
|
|
142
168
|
/**
|
|
143
169
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
144
170
|
*/
|
|
145
171
|
toNormalizeString() {
|
|
146
172
|
if (this.nameNode && this.equal && this.startQuote && this.valueNode && this.endQuote) {
|
|
147
|
-
return
|
|
148
|
-
this.equal.originRaw +
|
|
149
|
-
this.startQuote.originRaw +
|
|
150
|
-
this.valueNode.originRaw +
|
|
151
|
-
this.endQuote.originRaw);
|
|
173
|
+
return this.nameNode.raw + this.equal.raw + this.startQuote.raw + this.valueNode.raw + this.endQuote.raw;
|
|
152
174
|
}
|
|
153
175
|
return this.raw;
|
|
154
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns a string representation of the attribute.
|
|
179
|
+
*
|
|
180
|
+
* @implements DOM API: `Attr`
|
|
181
|
+
*
|
|
182
|
+
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name.
|
|
183
|
+
* @returns The string representation of the attribute.
|
|
184
|
+
*/
|
|
185
|
+
toString(fixed = false) {
|
|
186
|
+
if (!fixed) {
|
|
187
|
+
return this.raw;
|
|
188
|
+
}
|
|
189
|
+
if (this.localName === '#spread') {
|
|
190
|
+
return this.raw;
|
|
191
|
+
}
|
|
192
|
+
const tokens = [this.nameNode?.toString(true) ?? ''];
|
|
193
|
+
if (this.equal && this.equal.toString(true) !== '') {
|
|
194
|
+
tokens.push(this.spacesBeforeEqual?.toString(true) ?? '', this.equal?.toString(true) ?? '', this.spacesAfterEqual?.toString(true) ?? '', this.startQuote?.toString(true) ?? '', this.valueNode?.toString(true) ?? '', this.endQuote?.toString(true) ?? '');
|
|
195
|
+
}
|
|
196
|
+
else if (this.valueNode && this.valueNode.toString(true) !== '') {
|
|
197
|
+
tokens.push(
|
|
198
|
+
//
|
|
199
|
+
'=', this.startQuote?.toString(true) || '"', this.valueNode.toString(true), this.endQuote?.toString(true) || '"');
|
|
200
|
+
}
|
|
201
|
+
return tokens.join('');
|
|
202
|
+
}
|
|
155
203
|
}
|
|
156
204
|
_MLAttr_localName = new WeakMap(), _MLAttr_namespaceURI = new WeakMap(), _MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap();
|
package/lib/ml-dom/node/block.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { after, before, remove, replaceWith } from '../manipulations/child-node-methods.js';
|
|
2
2
|
import { MLNode } from './node.js';
|
|
3
3
|
export class MLBlock extends MLNode {
|
|
4
|
-
constructor(
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
|
-
astNode,
|
|
4
|
+
constructor(astNode,
|
|
7
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
6
|
document) {
|
|
9
7
|
super(astNode, document);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MLElement } from './element.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
3
3
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
4
|
import { MLNode } from './node.js';
|
|
5
|
-
export declare abstract class MLCharacterData<T extends RuleConfigValue, O extends PlainData = undefined, A extends
|
|
5
|
+
export declare abstract class MLCharacterData<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLNode<T, O, A> implements CharacterData {
|
|
6
6
|
/**
|
|
7
7
|
* @implements DOM API: `CharacterData`
|
|
8
8
|
* @see https://dom.spec.whatwg.org/#dom-characterdata-data
|