@markuplint/ml-core 4.0.0-dev.28 → 4.0.0-rc.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/LICENSE +1 -1
- package/lib/configs.browser.js +10 -8
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -2
- package/lib/ml-core.js +1 -0
- 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/get-indent.js +1 -1
- package/lib/ml-dom/manipulations/child-node-methods.js +1 -1
- package/lib/ml-dom/node/attr.d.ts +18 -0
- package/lib/ml-dom/node/attr.js +69 -31
- 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 +6 -4
- package/lib/ml-dom/node/document.js +13 -11
- package/lib/ml-dom/node/dom-token-list.js +3 -3
- 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 +14 -6
- package/lib/ml-dom/node/element.js +62 -46
- package/lib/ml-dom/node/named-node-map.js +1 -1
- package/lib/ml-dom/node/node-store.d.ts +3 -3
- package/lib/ml-dom/node/node.d.ts +2 -2
- package/lib/ml-dom/node/node.js +18 -11
- package/lib/ml-dom/node/parent-node.d.ts +2 -2
- package/lib/ml-dom/node/parent-node.js +1 -1
- package/lib/ml-dom/node/text.js +1 -1
- package/lib/ml-dom/node/types.d.ts +2 -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 +5 -5
- package/lib/ml-rule/ml-rule.d.ts +1 -1
- 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 +6 -2
- package/lib/types.d.ts +3 -3
- package/lib/utils/get-location-from-chars.js +1 -1
- package/package.json +13 -13
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -37
package/LICENSE
CHANGED
package/lib/configs.browser.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export async function getPreset(name) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
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
5
|
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
6
|
-
export * from './configs.js';
|
|
7
6
|
export * from './convert-ruleset.js';
|
|
8
7
|
export * from './ml-core.js';
|
|
9
8
|
export * from './ml-dom/index.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
4
|
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
5
|
-
export * from './configs.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.js
CHANGED
|
@@ -154,6 +154,7 @@ export class MLCore {
|
|
|
154
154
|
filename: __classPrivateFieldGet(this, _MLCore_filename, "f"),
|
|
155
155
|
endTag: __classPrivateFieldGet(this, _MLCore_parser, "f").endTag,
|
|
156
156
|
booleanish: __classPrivateFieldGet(this, _MLCore_parser, "f").booleanish,
|
|
157
|
+
tagNameCaseSensitive: __classPrivateFieldGet(this, _MLCore_parser, "f").tagNameCaseSensitive,
|
|
157
158
|
pretenders: __classPrivateFieldGet(this, _MLCore_pretenders, "f"),
|
|
158
159
|
}), "f");
|
|
159
160
|
}
|
|
@@ -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}"`);
|
|
@@ -26,7 +26,7 @@ node) {
|
|
|
26
26
|
if (node.isRawTextElementContent()) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
-
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+/);
|
|
30
30
|
if (matched) {
|
|
31
31
|
const spaces = matched[1];
|
|
32
32
|
if (spaces) {
|
|
@@ -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
|
@@ -14,11 +14,9 @@ import { resolveNamespace } from '@markuplint/ml-spec';
|
|
|
14
14
|
import { MLToken } from '../token/token.js';
|
|
15
15
|
import { MLDomTokenList } from './dom-token-list.js';
|
|
16
16
|
import { MLNode } from './node.js';
|
|
17
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
18
18
|
export class MLAttr extends MLNode {
|
|
19
|
-
constructor(
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
21
|
-
astToken,
|
|
19
|
+
constructor(astToken,
|
|
22
20
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
23
21
|
ownElement) {
|
|
24
22
|
super(astToken, ownElement.ownerMLDocument);
|
|
@@ -41,32 +39,35 @@ export class MLAttr extends MLNode {
|
|
|
41
39
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
42
40
|
*/
|
|
43
41
|
this.valueType = 'string';
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this
|
|
47
|
-
this.
|
|
48
|
-
this
|
|
49
|
-
this
|
|
50
|
-
this
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
this.candidate = this._astToken.candidate;
|
|
56
|
-
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f");
|
|
57
|
-
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.value.raw ?? '', "f");
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.valueType = this._astToken.valueType;
|
|
61
|
-
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
62
|
-
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f");
|
|
63
|
-
__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;
|
|
64
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;
|
|
65
68
|
const ns = resolveNamespace(__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI);
|
|
66
69
|
__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f");
|
|
67
70
|
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f");
|
|
68
|
-
this.ownerElement = ownElement;
|
|
69
|
-
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -149,18 +150,55 @@ export class MLAttr extends MLNode {
|
|
|
149
150
|
get value() {
|
|
150
151
|
return __classPrivateFieldGet(this, _MLAttr_potentialValue, "f");
|
|
151
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
|
+
}
|
|
152
168
|
/**
|
|
153
169
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
154
170
|
*/
|
|
155
171
|
toNormalizeString() {
|
|
156
172
|
if (this.nameNode && this.equal && this.startQuote && this.valueNode && this.endQuote) {
|
|
157
|
-
return
|
|
158
|
-
this.equal.originRaw +
|
|
159
|
-
this.startQuote.originRaw +
|
|
160
|
-
this.valueNode.originRaw +
|
|
161
|
-
this.endQuote.originRaw);
|
|
173
|
+
return this.nameNode.raw + this.equal.raw + this.startQuote.raw + this.valueNode.raw + this.endQuote.raw;
|
|
162
174
|
}
|
|
163
175
|
return this.raw;
|
|
164
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
|
+
}
|
|
165
203
|
}
|
|
166
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { after, before, nextElementSibling, previousElementSibling, remove, replaceWith, } from '../manipulations/child-node-methods.js';
|
|
2
2
|
import { MLNode } from './node.js';
|
|
3
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
3
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
4
4
|
export class MLCharacterData extends MLNode {
|
|
5
5
|
/**
|
|
6
6
|
* @implements DOM API: `CharacterData`
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { MLBlock } from './block.js';
|
|
2
2
|
import type { MLCharacterData } from './character-data.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MLComment } from './comment.js';
|
|
4
4
|
import type { MLElement } from './element.js';
|
|
5
5
|
import type { MLNode } from './node.js';
|
|
6
6
|
import type { MLText } from './text.js';
|
|
7
7
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
8
|
-
export type MLChildNode<T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
8
|
+
export type MLChildNode<T extends RuleConfigValue, O extends PlainData = undefined> = MLCharacterData<T, O> | MLComment<T, O> | MLText<T, O> | MLElement<T, O> | MLBlock<T, O>;
|
|
9
9
|
export declare function isChildNode<T extends RuleConfigValue, O extends PlainData = undefined>(node: MLNode<T, O>): node is MLChildNode<T, O>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DocumentFragmentNodeType } from './types.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 { MLParentNode } from './parent-node.js';
|
|
5
|
-
export declare class MLDocumentFragment<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O,
|
|
5
|
+
export declare class MLDocumentFragment<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTNode> implements DocumentFragment {
|
|
6
6
|
/**
|
|
7
7
|
* Returns a string appropriate for the type of node as `DocumentFragment`
|
|
8
8
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MLParentNode } from './parent-node.js';
|
|
2
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
2
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
3
3
|
export class MLDocumentFragment extends MLParentNode {
|
|
4
4
|
/**
|
|
5
5
|
* Returns a string appropriate for the type of node as `DocumentFragment`
|
|
@@ -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 MLDocumentType 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);
|
|
@@ -6,7 +6,7 @@ import type { MLNode } from './node.js';
|
|
|
6
6
|
import type { MLText } from './text.js';
|
|
7
7
|
import type { AccessibilityProperties, DocumentNodeType } from './types.js';
|
|
8
8
|
import type { MLRule } from '../../ml-rule/index.js';
|
|
9
|
-
import type Ruleset from '../../ruleset/index.js';
|
|
9
|
+
import type { Ruleset } from '../../ruleset/index.js';
|
|
10
10
|
import type { MLSchema } from '../../types.js';
|
|
11
11
|
import type { Walker } from '../helper/walkers.js';
|
|
12
12
|
import type { MLToken } from '../token/token.js';
|
|
@@ -55,6 +55,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
55
55
|
*
|
|
56
56
|
*/
|
|
57
57
|
readonly specs: MLMLSpec;
|
|
58
|
+
readonly tagNameCaseSensitive: boolean;
|
|
58
59
|
/**
|
|
59
60
|
*
|
|
60
61
|
* @param ast node list of markuplint AST
|
|
@@ -64,6 +65,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
64
65
|
readonly filename?: string;
|
|
65
66
|
readonly endTag?: 'xml' | 'omittable' | 'never';
|
|
66
67
|
readonly booleanish?: boolean;
|
|
68
|
+
readonly tagNameCaseSensitive?: boolean;
|
|
67
69
|
readonly pretenders?: readonly Pretender[];
|
|
68
70
|
});
|
|
69
71
|
/**
|
|
@@ -1479,7 +1481,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
1479
1481
|
/**
|
|
1480
1482
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
1481
1483
|
*/
|
|
1482
|
-
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").
|
|
1484
|
+
getTokenList(): readonly MLToken<import("@markuplint/ml-ast").MLASTToken>[];
|
|
1483
1485
|
/**
|
|
1484
1486
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1485
1487
|
*
|
|
@@ -1566,7 +1568,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
1566
1568
|
/**
|
|
1567
1569
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
1568
1570
|
*/
|
|
1569
|
-
searchNodeByLocation(line: number, col: number): MLNode<T, O, import("@markuplint/ml-ast").
|
|
1571
|
+
searchNodeByLocation(line: number, col: number): MLNode<T, O, import("@markuplint/ml-ast").MLASTNode> | null;
|
|
1570
1572
|
/**
|
|
1571
1573
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
1572
1574
|
*/
|
|
@@ -1574,7 +1576,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
1574
1576
|
/**
|
|
1575
1577
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
1576
1578
|
*/
|
|
1577
|
-
toString(): string;
|
|
1579
|
+
toString(fixed?: boolean): string;
|
|
1578
1580
|
/**
|
|
1579
1581
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
1580
1582
|
*/
|
|
@@ -21,7 +21,7 @@ import { sequentialWalker, syncWalk } from '../helper/walkers.js';
|
|
|
21
21
|
import { nodeListToHTMLCollection } from './node-list.js';
|
|
22
22
|
import { MLParentNode } from './parent-node.js';
|
|
23
23
|
import { RuleMapper } from './rule-mapper.js';
|
|
24
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
24
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
25
25
|
const log = coreLog.extend('ml-dom');
|
|
26
26
|
const docLog = log.extend('document');
|
|
27
27
|
const ruleLog = docLog.extend('rule');
|
|
@@ -31,9 +31,7 @@ export class MLDocument extends MLParentNode {
|
|
|
31
31
|
* @param ast node list of markuplint AST
|
|
32
32
|
* @param ruleset ruleset object
|
|
33
33
|
*/
|
|
34
|
-
constructor(
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
36
|
-
ast, ruleset, schemas, options) {
|
|
34
|
+
constructor(ast, ruleset, schemas, options) {
|
|
37
35
|
// @ts-ignore
|
|
38
36
|
super(ast, null);
|
|
39
37
|
/**
|
|
@@ -50,6 +48,7 @@ export class MLDocument extends MLParentNode {
|
|
|
50
48
|
this.booleanish = options?.booleanish ?? false;
|
|
51
49
|
this.endTag = options?.endTag ?? 'omittable';
|
|
52
50
|
__classPrivateFieldSet(this, _MLDocument_filename, options?.filename, "f");
|
|
51
|
+
this.tagNameCaseSensitive = options?.tagNameCaseSensitive ?? false;
|
|
53
52
|
// console.log(ast.nodeList.map((n, i) => `${i}: ${n.uuid} "${n.raw.trim()}"(${n.type})`));
|
|
54
53
|
this.nodeList = Object.freeze(ast.nodeList
|
|
55
54
|
.map(astNode => {
|
|
@@ -2090,12 +2089,18 @@ export class MLDocument extends MLParentNode {
|
|
|
2090
2089
|
/**
|
|
2091
2090
|
* @implements `@markuplint/ml-core` API: `MLDocument`
|
|
2092
2091
|
*/
|
|
2093
|
-
toString() {
|
|
2094
|
-
|
|
2092
|
+
toString(fixed = false) {
|
|
2093
|
+
if (!fixed) {
|
|
2094
|
+
return this.raw;
|
|
2095
|
+
}
|
|
2096
|
+
let raw = this.raw;
|
|
2097
|
+
let offset = 0;
|
|
2095
2098
|
for (const node of this.getTokenList()) {
|
|
2096
|
-
|
|
2099
|
+
const nodeRaw = node.toString(true);
|
|
2100
|
+
raw = raw.slice(0, node.startOffset + offset) + nodeRaw + raw.slice(node.endOffset + offset);
|
|
2101
|
+
offset += nodeRaw.length - (node.endOffset - node.startOffset);
|
|
2097
2102
|
}
|
|
2098
|
-
return
|
|
2103
|
+
return raw;
|
|
2099
2104
|
}
|
|
2100
2105
|
walkOn(type, walker, skipWhenRuleIsDisabled = true) {
|
|
2101
2106
|
return sequentialWalker(this.nodeList, node => {
|
|
@@ -2141,9 +2146,6 @@ export class MLDocument extends MLParentNode {
|
|
|
2141
2146
|
if (docLog.enabled) {
|
|
2142
2147
|
docLog('Pretending: %O', pretenders);
|
|
2143
2148
|
}
|
|
2144
|
-
if (!pretenders) {
|
|
2145
|
-
return;
|
|
2146
|
-
}
|
|
2147
2149
|
for (const node of this.nodeList) {
|
|
2148
2150
|
if (node.is(node.ELEMENT_NODE)) {
|
|
2149
2151
|
node.pretending(pretenders);
|
|
@@ -10,8 +10,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _MLDomTokenList_origin, _MLDomTokenList_ownerAttrs, _MLDomTokenList_set;
|
|
13
|
-
import { getCol, getLine } from '@markuplint/parser-utils';
|
|
14
|
-
import UnexpectedCallError from './unexpected-call-error.js';
|
|
13
|
+
import { getCol, getLine } from '@markuplint/parser-utils/location';
|
|
14
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
15
15
|
export class MLDomTokenList extends Array {
|
|
16
16
|
constructor(tokens,
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
@@ -114,7 +114,7 @@ export class MLDomTokenList extends Array {
|
|
|
114
114
|
throw new UnexpectedCallError('Not supported "toggle" method');
|
|
115
115
|
}
|
|
116
116
|
_pick(token, _offset = 0) {
|
|
117
|
-
token = token.trim().split(/\s+/
|
|
117
|
+
token = token.trim().split(/\s+/)[0] ?? '';
|
|
118
118
|
if (!token) {
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MLDocument } from './document.js';
|
|
2
|
+
import type { MLElement } from './element.js';
|
|
3
|
+
import type { MLASTElementCloseTag } from '@markuplint/ml-ast';
|
|
4
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
+
import { MLNode } from './node.js';
|
|
6
|
+
export declare class MLElementCloseTag<T extends RuleConfigValue, O extends PlainData = undefined> extends MLNode<T, O, MLASTElementCloseTag> {
|
|
7
|
+
readonly pair: MLElement<T, O>;
|
|
8
|
+
constructor(astNode: MLASTElementCloseTag, document: MLDocument<T, O>, pair: MLElement<T, O>);
|
|
9
|
+
/**
|
|
10
|
+
* Returns a string appropriate for the type of node as `MLBlock`
|
|
11
|
+
*
|
|
12
|
+
* @implements `@markuplint/ml-core` API: `MLBlock`
|
|
13
|
+
*/
|
|
14
|
+
get nodeName(): string;
|
|
15
|
+
/**
|
|
16
|
+
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
17
|
+
*/
|
|
18
|
+
get rawName(): string;
|
|
19
|
+
toString(fixed?: boolean): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MLNode } from './node.js';
|
|
2
|
+
export class MLElementCloseTag extends MLNode {
|
|
3
|
+
constructor(astNode,
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
5
|
+
document,
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
7
|
+
pair) {
|
|
8
|
+
super(astNode, document);
|
|
9
|
+
this.pair = pair;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns a string appropriate for the type of node as `MLBlock`
|
|
13
|
+
*
|
|
14
|
+
* @implements `@markuplint/ml-core` API: `MLBlock`
|
|
15
|
+
*/
|
|
16
|
+
get nodeName() {
|
|
17
|
+
return this.pair.nodeName;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
21
|
+
*/
|
|
22
|
+
get rawName() {
|
|
23
|
+
return this._astToken.nodeName;
|
|
24
|
+
}
|
|
25
|
+
toString(fixed = false) {
|
|
26
|
+
if (!fixed) {
|
|
27
|
+
return this.raw;
|
|
28
|
+
}
|
|
29
|
+
if (this.pair.isOmitted) {
|
|
30
|
+
return this.raw;
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
this.pair.tagOpenChar,
|
|
34
|
+
this.pair.tagOpenChar === '' ? '' : '/',
|
|
35
|
+
this.pair.fixedNodeName === this.pair.rawName ? this.rawName : this.pair.fixedNodeName,
|
|
36
|
+
this.pair.tagCloseChar,
|
|
37
|
+
].join('');
|
|
38
|
+
}
|
|
39
|
+
}
|