@markuplint/parser-utils 3.13.0 → 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/attr-tokenizer.d.ts +18 -0
- package/lib/attr-tokenizer.js +169 -0
- package/lib/const.d.ts +9 -2
- package/lib/const.js +12 -9
- package/lib/debugger.d.ts +3 -2
- package/lib/debugger.js +38 -39
- package/lib/decision.js +6 -11
- package/lib/detect-element-type.d.ts +1 -5
- package/lib/detect-element-type.js +4 -8
- package/lib/enums.d.ts +16 -0
- package/lib/enums.js +18 -0
- package/lib/get-location.d.ts +4 -17
- package/lib/get-location.js +11 -31
- package/lib/idl-attributes.d.ts +2 -2
- package/lib/idl-attributes.js +5 -10
- package/lib/ignore-block.d.ts +4 -3
- package/lib/ignore-block.js +75 -131
- package/lib/ignore-front-matter.d.ts +4 -1
- package/lib/ignore-front-matter.js +15 -10
- package/lib/index.d.ts +7 -16
- package/lib/index.js +7 -19
- package/lib/parser-error.d.ts +19 -24
- package/lib/parser-error.js +8 -15
- package/lib/parser.d.ts +108 -0
- package/lib/parser.js +1076 -0
- package/lib/script-parser.d.ts +6 -0
- package/lib/script-parser.js +22 -0
- package/lib/sort-nodes.d.ts +2 -0
- package/lib/sort-nodes.js +18 -0
- package/lib/types.d.ts +50 -12
- package/lib/types.js +1 -2
- package/package.json +17 -8
- package/lib/create-token.d.ts +0 -9
- package/lib/create-token.js +0 -35
- package/lib/flatten-nodes.d.ts +0 -2
- package/lib/flatten-nodes.js +0 -251
- package/lib/get-space-before.d.ts +0 -1
- package/lib/get-space-before.js +0 -13
- package/lib/idl-attributes.test.d.ts +0 -1
- package/lib/idl-attributes.test.js +0 -45
- package/lib/parse-attr.d.ts +0 -27
- package/lib/parse-attr.js +0 -150
- package/lib/remove-deprecated-node.d.ts +0 -7
- package/lib/remove-deprecated-node.js +0 -43
- package/lib/siblings-correction.d.ts +0 -9
- package/lib/siblings-correction.js +0 -26
- package/lib/tag-splitter.d.ts +0 -7
- package/lib/tag-splitter.js +0 -92
- package/lib/walker.d.ts +0 -2
- package/lib/walker.js +0 -22
- package/test/create-token.spec.js +0 -17
- package/test/flatten-nodes.spec.js +0 -31
- package/test/get-location.spec.js +0 -38
- package/test/ignore-block.spec.js +0 -274
- package/test/ignore-front-matter.spec.js +0 -20
- package/test/parse-attr.spec.js +0 -68
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function scriptParser(script: string): ScriptTokenType[];
|
|
2
|
+
export declare function removeQuote(str: string): string;
|
|
3
|
+
export type ScriptTokenType = {
|
|
4
|
+
type: 'Identifier' | 'Boolean' | 'Numeric' | 'String' | 'Template' | 'Punctuator';
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { tokenize } from 'espree';
|
|
3
|
+
export function scriptParser(script) {
|
|
4
|
+
const tokens = tokenize(script, {
|
|
5
|
+
ecmaVersion: 'latest',
|
|
6
|
+
loc: false,
|
|
7
|
+
});
|
|
8
|
+
return tokens.map((token) => ({
|
|
9
|
+
type: token.type,
|
|
10
|
+
value: token.value,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
export function removeQuote(str) {
|
|
14
|
+
const quote = str[0];
|
|
15
|
+
if (quote !== '"' && quote !== "'" && quote !== '`') {
|
|
16
|
+
return str;
|
|
17
|
+
}
|
|
18
|
+
if (str.at(-1) !== quote) {
|
|
19
|
+
return str;
|
|
20
|
+
}
|
|
21
|
+
return str.slice(1, -1);
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function sortNodes(a, b) {
|
|
2
|
+
if (a.startOffset === b.startOffset) {
|
|
3
|
+
return sort(a, b, 'endOffset');
|
|
4
|
+
}
|
|
5
|
+
return sort(a, b, 'startOffset');
|
|
6
|
+
}
|
|
7
|
+
function sort(a, b, key) {
|
|
8
|
+
if (Number.isNaN(a[key]) || Number.isNaN(b[key])) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
if (a[key] < b[key]) {
|
|
12
|
+
return -1;
|
|
13
|
+
}
|
|
14
|
+
if (a[key] > b[key]) {
|
|
15
|
+
return 1;
|
|
16
|
+
}
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,18 +1,56 @@
|
|
|
1
|
+
import type { EndTagType, MLASTParentNode, ParserOptions as ConfigParserOptions } from '@markuplint/ml-ast';
|
|
2
|
+
export type ParserOptions = {
|
|
3
|
+
readonly booleanish?: boolean;
|
|
4
|
+
readonly endTagType?: EndTagType;
|
|
5
|
+
readonly ignoreTags?: readonly IgnoreTag[];
|
|
6
|
+
readonly maskChar?: string;
|
|
7
|
+
readonly tagNameCaseSensitive?: boolean;
|
|
8
|
+
readonly selfCloseType?: SelfCloseType;
|
|
9
|
+
readonly spaceChars?: readonly string[];
|
|
10
|
+
readonly rawTextElements?: readonly string[];
|
|
11
|
+
};
|
|
12
|
+
export type ParseOptions = ConfigParserOptions & {
|
|
13
|
+
readonly offsetOffset?: number;
|
|
14
|
+
readonly offsetLine?: number;
|
|
15
|
+
readonly offsetColumn?: number;
|
|
16
|
+
readonly depth?: number;
|
|
17
|
+
};
|
|
18
|
+
export type Tokenized<N extends {} = {}, State extends unknown = null> = {
|
|
19
|
+
readonly ast: N[];
|
|
20
|
+
readonly isFragment: boolean;
|
|
21
|
+
readonly state?: State;
|
|
22
|
+
};
|
|
23
|
+
export type Token = {
|
|
24
|
+
readonly raw: string;
|
|
25
|
+
readonly startOffset: number;
|
|
26
|
+
readonly startLine: number;
|
|
27
|
+
readonly startCol: number;
|
|
28
|
+
};
|
|
29
|
+
export type ChildToken = Token & {
|
|
30
|
+
readonly depth: number;
|
|
31
|
+
readonly parentNode: MLASTParentNode | null;
|
|
32
|
+
};
|
|
33
|
+
export type SelfCloseType = 'html' | 'xml' | 'html+xml';
|
|
1
34
|
export type Code = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
35
|
+
readonly type: string;
|
|
36
|
+
readonly index: number;
|
|
37
|
+
readonly startTag: string;
|
|
38
|
+
readonly taggedCode: string;
|
|
39
|
+
readonly endTag: string | null;
|
|
40
|
+
resolved: boolean;
|
|
7
41
|
};
|
|
8
42
|
export type IgnoreTag = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
43
|
+
readonly type: string;
|
|
44
|
+
readonly start: Readonly<RegExp> | string;
|
|
45
|
+
readonly end: Readonly<RegExp> | string;
|
|
12
46
|
};
|
|
13
47
|
export type IgnoreBlock = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
48
|
+
readonly source: string;
|
|
49
|
+
readonly replaced: string;
|
|
50
|
+
readonly stack: readonly Code[];
|
|
51
|
+
readonly maskChar: string;
|
|
52
|
+
};
|
|
53
|
+
export type QuoteSet = {
|
|
54
|
+
readonly start: string;
|
|
55
|
+
readonly end: string;
|
|
18
56
|
};
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/parser-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.10",
|
|
4
4
|
"description": "Utility module for markuplint parser plugin",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./location": {
|
|
15
|
+
"import": "./lib/get-location.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"types": "lib/index.d.ts",
|
|
11
19
|
"publishConfig": {
|
|
12
20
|
"access": "public"
|
|
@@ -19,12 +27,13 @@
|
|
|
19
27
|
"clean": "tsc --build --clean"
|
|
20
28
|
},
|
|
21
29
|
"dependencies": {
|
|
22
|
-
"@markuplint/ml-ast": "
|
|
23
|
-
"@markuplint/
|
|
24
|
-
"@types
|
|
25
|
-
"
|
|
26
|
-
"
|
|
30
|
+
"@markuplint/ml-ast": "4.0.0-alpha.10",
|
|
31
|
+
"@markuplint/ml-spec": "4.0.0-alpha.10",
|
|
32
|
+
"@markuplint/types": "4.0.0-alpha.10",
|
|
33
|
+
"@types/uuid": "^9.0.8",
|
|
34
|
+
"espree": "^10.0.0",
|
|
35
|
+
"type-fest": "^4.10.1",
|
|
27
36
|
"uuid": "^9.0.1"
|
|
28
37
|
},
|
|
29
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
|
|
30
39
|
}
|
package/lib/create-token.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MLToken } from '@markuplint/ml-ast';
|
|
2
|
-
export declare function tokenizer(
|
|
3
|
-
raw: string | null,
|
|
4
|
-
startLine: number,
|
|
5
|
-
startCol: number,
|
|
6
|
-
startOffset: number,
|
|
7
|
-
): MLToken;
|
|
8
|
-
export declare function createTokenFromRawCode(raw: string | null, startOffset: number, rawCode: string): MLToken;
|
|
9
|
-
export declare function uuid(): string;
|
package/lib/create-token.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuid = exports.createTokenFromRawCode = exports.tokenizer = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const get_location_1 = require("./get-location");
|
|
6
|
-
function tokenizer(raw, startLine, startCol, startOffset) {
|
|
7
|
-
raw = raw !== null && raw !== void 0 ? raw : '';
|
|
8
|
-
const endLine = (0, get_location_1.getEndLine)(raw, startLine);
|
|
9
|
-
const endCol = (0, get_location_1.getEndCol)(raw, startCol);
|
|
10
|
-
const endOffset = startOffset + raw.length;
|
|
11
|
-
return {
|
|
12
|
-
uuid: uuid(),
|
|
13
|
-
raw,
|
|
14
|
-
startOffset,
|
|
15
|
-
endOffset,
|
|
16
|
-
startLine,
|
|
17
|
-
endLine,
|
|
18
|
-
startCol,
|
|
19
|
-
endCol,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
exports.tokenizer = tokenizer;
|
|
23
|
-
function createTokenFromRawCode(raw, startOffset, rawCode) {
|
|
24
|
-
raw = raw !== null && raw !== void 0 ? raw : '';
|
|
25
|
-
const loc = (0, get_location_1.sliceFragment)(rawCode, startOffset, startOffset + raw.length);
|
|
26
|
-
return {
|
|
27
|
-
uuid: uuid(),
|
|
28
|
-
...loc,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.createTokenFromRawCode = createTokenFromRawCode;
|
|
32
|
-
function uuid() {
|
|
33
|
-
return (0, uuid_1.v4)();
|
|
34
|
-
}
|
|
35
|
-
exports.uuid = uuid;
|
package/lib/flatten-nodes.d.ts
DELETED
package/lib/flatten-nodes.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenNodes = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const remove_deprecated_node_1 = require("./remove-deprecated-node");
|
|
6
|
-
const tag_splitter_1 = tslib_1.__importDefault(require("./tag-splitter"));
|
|
7
|
-
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
8
|
-
function flattenNodes(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
|
-
nodeTree, rawHtml, createLastText = true) {
|
|
11
|
-
var _a, _b, _c, _d;
|
|
12
|
-
const nodeOrders = arrayize(nodeTree, rawHtml);
|
|
13
|
-
{
|
|
14
|
-
/**
|
|
15
|
-
* Correction prev/next/parent
|
|
16
|
-
*/
|
|
17
|
-
let prevToken = null;
|
|
18
|
-
for (const node of nodeOrders) {
|
|
19
|
-
if (!prevToken) {
|
|
20
|
-
prevToken = node;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (node.type !== 'endtag') {
|
|
24
|
-
prevToken = node;
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const endTag = node;
|
|
28
|
-
if (endTag.nodeName.toLowerCase() === 'body' && prevToken.type === 'text') {
|
|
29
|
-
const prevWreckagesText = prevToken;
|
|
30
|
-
const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
|
|
31
|
-
if (wreckages.length > 0 && wreckages[0]) {
|
|
32
|
-
// console.log('wreckages\n', wreckages);
|
|
33
|
-
const lastText = wreckages[0];
|
|
34
|
-
const raw = lastText.raw;
|
|
35
|
-
const startLine = lastText.line;
|
|
36
|
-
const startCol = lastText.col;
|
|
37
|
-
prevWreckagesText.raw = raw;
|
|
38
|
-
prevWreckagesText.endOffset = prevWreckagesText.startOffset + raw.length;
|
|
39
|
-
prevWreckagesText.startLine = startLine;
|
|
40
|
-
prevWreckagesText.endLine = (0, parser_utils_1.getEndLine)(raw, startLine);
|
|
41
|
-
prevWreckagesText.startCol = startCol;
|
|
42
|
-
prevWreckagesText.endCol = (0, parser_utils_1.getEndCol)(raw, startCol);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
(0, remove_deprecated_node_1.removeDeprecatedNode)(nodeOrders);
|
|
48
|
-
{
|
|
49
|
-
/**
|
|
50
|
-
* getting last node
|
|
51
|
-
*/
|
|
52
|
-
let lastNode = null;
|
|
53
|
-
for (const node of nodeOrders) {
|
|
54
|
-
if (node.isGhost) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
lastNode = node;
|
|
58
|
-
}
|
|
59
|
-
if (lastNode) {
|
|
60
|
-
if (lastNode.type === 'text') {
|
|
61
|
-
// Correction for Parse5 AST
|
|
62
|
-
// prev node: ? -> html
|
|
63
|
-
lastNode.prevNode = (_b = (_a = lastNode.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) !== null && _b !== void 0 ? _b : lastNode.parentNode;
|
|
64
|
-
if (lastNode.prevNode) {
|
|
65
|
-
lastNode.prevNode.nextNode = lastNode;
|
|
66
|
-
}
|
|
67
|
-
// parent node: body -> null
|
|
68
|
-
lastNode.parentNode = null;
|
|
69
|
-
// next node: ? -> null
|
|
70
|
-
lastNode.nextNode = null;
|
|
71
|
-
}
|
|
72
|
-
else if (createLastText) {
|
|
73
|
-
/**
|
|
74
|
-
* create Last spaces
|
|
75
|
-
*/
|
|
76
|
-
let lastOffset = 0;
|
|
77
|
-
nodeOrders.forEach((node, i) => {
|
|
78
|
-
lastOffset = Math.max(node.endOffset, lastOffset);
|
|
79
|
-
});
|
|
80
|
-
// console.log(lastOffset);
|
|
81
|
-
const lastTextContent = rawHtml.slice(lastOffset);
|
|
82
|
-
// console.log(`"${lastTextContent}"`);
|
|
83
|
-
if (lastTextContent) {
|
|
84
|
-
const line = (_c = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endLine) !== null && _c !== void 0 ? _c : 0;
|
|
85
|
-
const col = (_d = lastNode === null || lastNode === void 0 ? void 0 : lastNode.endCol) !== null && _d !== void 0 ? _d : 0;
|
|
86
|
-
const lastTextNode = {
|
|
87
|
-
uuid: (0, parser_utils_1.uuid)(),
|
|
88
|
-
raw: lastTextContent,
|
|
89
|
-
startOffset: lastOffset,
|
|
90
|
-
endOffset: lastOffset + lastTextContent.length,
|
|
91
|
-
startLine: line,
|
|
92
|
-
endLine: (0, parser_utils_1.getEndLine)(lastTextContent, line),
|
|
93
|
-
startCol: col,
|
|
94
|
-
endCol: (0, parser_utils_1.getEndCol)(lastTextContent, col),
|
|
95
|
-
nodeName: '#text',
|
|
96
|
-
type: 'text',
|
|
97
|
-
parentNode: null,
|
|
98
|
-
prevNode: lastNode,
|
|
99
|
-
nextNode: null,
|
|
100
|
-
isFragment: false,
|
|
101
|
-
isGhost: false,
|
|
102
|
-
};
|
|
103
|
-
lastNode.nextNode = lastTextNode;
|
|
104
|
-
if ((lastNode.type === 'starttag' || lastNode.type === 'endtag') && lastNode.pearNode) {
|
|
105
|
-
lastNode.pearNode.nextNode = lastTextNode;
|
|
106
|
-
}
|
|
107
|
-
nodeOrders.push(lastTextNode);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* concat text nodes
|
|
114
|
-
*/
|
|
115
|
-
const result = [];
|
|
116
|
-
nodeOrders.forEach(node => {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
const prevNode = (_a = result[result.length - 1]) !== null && _a !== void 0 ? _a : null;
|
|
119
|
-
if (node.type === 'text' && (prevNode === null || prevNode === void 0 ? void 0 : prevNode.type) === 'text') {
|
|
120
|
-
prevNode.raw = prevNode.raw + node.raw;
|
|
121
|
-
prevNode.endOffset = node.endOffset;
|
|
122
|
-
prevNode.endLine = node.endLine;
|
|
123
|
-
prevNode.endCol = node.endCol;
|
|
124
|
-
prevNode.nextNode = node.nextNode;
|
|
125
|
-
if (prevNode.parentNode) {
|
|
126
|
-
if (prevNode.parentNode.childNodes) {
|
|
127
|
-
if (prevNode.parentNode.childNodes.findIndex(currentChild => currentChild.uuid === prevNode.uuid) === -1) {
|
|
128
|
-
prevNode.parentNode.childNodes.unshift(prevNode);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
prevNode.parentNode.childNodes = [prevNode];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
prevNode.parentNode.childNodes = (_b = prevNode.parentNode.childNodes) === null || _b === void 0 ? void 0 : _b.filter(n => n.uuid !== node.uuid);
|
|
135
|
-
}
|
|
136
|
-
if (node.nextNode) {
|
|
137
|
-
node.nextNode.prevNode = prevNode;
|
|
138
|
-
}
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
result.push(node);
|
|
142
|
-
});
|
|
143
|
-
{
|
|
144
|
-
/**
|
|
145
|
-
* Correction prev/next/parent
|
|
146
|
-
*/
|
|
147
|
-
let prevToken = null;
|
|
148
|
-
for (const node of result) {
|
|
149
|
-
if (!prevToken) {
|
|
150
|
-
prevToken = node;
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
if (((prevToken.type === 'endtag' && prevToken.nodeName.toLowerCase() === 'body') ||
|
|
154
|
-
prevToken.type === 'doctype') &&
|
|
155
|
-
node.type === 'text') {
|
|
156
|
-
const nextNode = prevToken.nextNode;
|
|
157
|
-
prevToken.nextNode = node;
|
|
158
|
-
if (prevToken.type === 'endtag' && prevToken.pearNode) {
|
|
159
|
-
prevToken.pearNode.nextNode = node;
|
|
160
|
-
}
|
|
161
|
-
node.prevNode = prevToken;
|
|
162
|
-
node.nextNode = nextNode;
|
|
163
|
-
node.parentNode = prevToken.parentNode;
|
|
164
|
-
}
|
|
165
|
-
// EndTag
|
|
166
|
-
if (node.type === 'starttag' && node.pearNode) {
|
|
167
|
-
const endTag = node.pearNode;
|
|
168
|
-
endTag.pearNode = node;
|
|
169
|
-
endTag.prevNode = node.prevNode;
|
|
170
|
-
endTag.nextNode = node.nextNode;
|
|
171
|
-
}
|
|
172
|
-
// Children
|
|
173
|
-
if (node.type === 'text') {
|
|
174
|
-
const parent = node.parentNode;
|
|
175
|
-
if (parent && parent.type === 'starttag' && parent.nodeName.toLowerCase() === 'html') {
|
|
176
|
-
if (parent.childNodes && !parent.childNodes.some(n => n.uuid === node.uuid)) {
|
|
177
|
-
parent.childNodes.push(node);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
prevToken = node;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// console.log(nodeOrders.map((n, i) => `${i}: ${n.raw.trim()}`));
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
exports.flattenNodes = flattenNodes;
|
|
188
|
-
function arrayize(
|
|
189
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
190
|
-
nodeTree, rawHtml) {
|
|
191
|
-
const nodeOrders = [];
|
|
192
|
-
let prevLine = 1;
|
|
193
|
-
let prevCol = 1;
|
|
194
|
-
let currentEndOffset = 0;
|
|
195
|
-
/**
|
|
196
|
-
* pushing list
|
|
197
|
-
*/
|
|
198
|
-
(0, parser_utils_1.walk)(nodeTree, node => {
|
|
199
|
-
var _a;
|
|
200
|
-
const diff = node.startOffset - currentEndOffset;
|
|
201
|
-
if (diff > 0) {
|
|
202
|
-
const html = rawHtml.slice(currentEndOffset, node.startOffset);
|
|
203
|
-
/**
|
|
204
|
-
* first white spaces
|
|
205
|
-
*/
|
|
206
|
-
if (/^\s+$/.test(html)) {
|
|
207
|
-
const spaces = html;
|
|
208
|
-
const textNode = {
|
|
209
|
-
uuid: (0, parser_utils_1.uuid)(),
|
|
210
|
-
raw: spaces,
|
|
211
|
-
startOffset: currentEndOffset,
|
|
212
|
-
endOffset: currentEndOffset + spaces.length,
|
|
213
|
-
startLine: prevLine,
|
|
214
|
-
endLine: (0, parser_utils_1.getEndLine)(spaces, prevLine),
|
|
215
|
-
startCol: prevCol,
|
|
216
|
-
endCol: (0, parser_utils_1.getEndCol)(spaces, prevCol),
|
|
217
|
-
nodeName: '#text',
|
|
218
|
-
type: 'text',
|
|
219
|
-
parentNode: node.parentNode,
|
|
220
|
-
prevNode: node.prevNode,
|
|
221
|
-
nextNode: node,
|
|
222
|
-
isFragment: false,
|
|
223
|
-
isGhost: false,
|
|
224
|
-
};
|
|
225
|
-
node.prevNode = textNode;
|
|
226
|
-
if (node.parentNode && node.parentNode.childNodes) {
|
|
227
|
-
const newChildNodes = [...node.parentNode.childNodes];
|
|
228
|
-
if (newChildNodes.some(child => {
|
|
229
|
-
return (
|
|
230
|
-
// Out of start offset
|
|
231
|
-
textNode.endOffset < child.startOffset ||
|
|
232
|
-
// Out of end offset
|
|
233
|
-
child.endOffset < textNode.startOffset);
|
|
234
|
-
})) {
|
|
235
|
-
newChildNodes.push(textNode);
|
|
236
|
-
}
|
|
237
|
-
newChildNodes.sort((a, b) => a.startOffset - b.startOffset);
|
|
238
|
-
node.parentNode.childNodes = newChildNodes;
|
|
239
|
-
}
|
|
240
|
-
nodeOrders.push(textNode);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
currentEndOffset = node.startOffset + node.raw.length;
|
|
244
|
-
prevLine = node.endLine;
|
|
245
|
-
prevCol = node.endCol;
|
|
246
|
-
// for ghost nodes
|
|
247
|
-
node.endOffset = (_a = node.endOffset) !== null && _a !== void 0 ? _a : currentEndOffset;
|
|
248
|
-
nodeOrders.push(node);
|
|
249
|
-
});
|
|
250
|
-
return nodeOrders.slice();
|
|
251
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getSpaceBefore(offset: number, rawCode: string): import('@markuplint/ml-ast').MLToken;
|
package/lib/get-space-before.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpaceBefore = void 0;
|
|
4
|
-
const create_token_1 = require("./create-token");
|
|
5
|
-
function getSpaceBefore(offset, rawCode) {
|
|
6
|
-
var _a;
|
|
7
|
-
const aboveCode = rawCode.slice(0, offset);
|
|
8
|
-
const aboveAttrMatched = aboveCode.match(/\s+$/m);
|
|
9
|
-
const aboveAttrChar = (_a = aboveAttrMatched === null || aboveAttrMatched === void 0 ? void 0 : aboveAttrMatched[0]) !== null && _a !== void 0 ? _a : '';
|
|
10
|
-
const spacesBefore = (0, create_token_1.createTokenFromRawCode)(aboveAttrChar, offset - aboveAttrChar.length, rawCode);
|
|
11
|
-
return spacesBefore;
|
|
12
|
-
}
|
|
13
|
-
exports.getSpaceBefore = getSpaceBefore;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const idl_attributes_1 = require("./idl-attributes");
|
|
4
|
-
it('basic', () => {
|
|
5
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('class')).toStrictEqual({
|
|
6
|
-
idlPropName: 'className',
|
|
7
|
-
contentAttrName: 'class',
|
|
8
|
-
});
|
|
9
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('for')).toStrictEqual({
|
|
10
|
-
idlPropName: 'htmlFor',
|
|
11
|
-
contentAttrName: 'for',
|
|
12
|
-
});
|
|
13
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('className')).toStrictEqual({
|
|
14
|
-
idlPropName: 'className',
|
|
15
|
-
contentAttrName: 'class',
|
|
16
|
-
});
|
|
17
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('htmlFor')).toStrictEqual({
|
|
18
|
-
idlPropName: 'htmlFor',
|
|
19
|
-
contentAttrName: 'for',
|
|
20
|
-
});
|
|
21
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('tabindex')).toStrictEqual({
|
|
22
|
-
idlPropName: 'tabIndex',
|
|
23
|
-
contentAttrName: 'tabindex',
|
|
24
|
-
});
|
|
25
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('tab-index')).toStrictEqual({
|
|
26
|
-
idlPropName: 'tabIndex',
|
|
27
|
-
contentAttrName: 'tabindex',
|
|
28
|
-
});
|
|
29
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('TabIndex')).toStrictEqual({
|
|
30
|
-
idlPropName: 'tabIndex',
|
|
31
|
-
contentAttrName: 'tabindex',
|
|
32
|
-
});
|
|
33
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('x')).toStrictEqual({
|
|
34
|
-
idlPropName: 'x',
|
|
35
|
-
contentAttrName: 'x',
|
|
36
|
-
});
|
|
37
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('y')).toStrictEqual({
|
|
38
|
-
idlPropName: 'y',
|
|
39
|
-
contentAttrName: 'y',
|
|
40
|
-
});
|
|
41
|
-
expect((0, idl_attributes_1.searchIDLAttribute)('attribute-name')).toStrictEqual({
|
|
42
|
-
idlPropName: 'attributeName',
|
|
43
|
-
contentAttrName: 'attributeName',
|
|
44
|
-
});
|
|
45
|
-
});
|
package/lib/parse-attr.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
|
|
2
|
-
type ParseAttrOptions = {
|
|
3
|
-
readonly booleanish?: boolean;
|
|
4
|
-
readonly valueDelimiters?: readonly ValueDelimiter[];
|
|
5
|
-
readonly equal?: string;
|
|
6
|
-
};
|
|
7
|
-
type ValueDelimiter = {
|
|
8
|
-
readonly start: string;
|
|
9
|
-
readonly end: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const defaultValueDelimiters: readonly ValueDelimiter[];
|
|
12
|
-
export declare function parseAttr(raw: string, offset: number, html: string, options?: ParseAttrOptions): MLASTHTMLAttr;
|
|
13
|
-
export declare function tokenize(
|
|
14
|
-
raw: string,
|
|
15
|
-
options?: ParseAttrOptions,
|
|
16
|
-
): {
|
|
17
|
-
beforeName: string;
|
|
18
|
-
name: string;
|
|
19
|
-
afterName: string;
|
|
20
|
-
equal: string;
|
|
21
|
-
beforeValue: string;
|
|
22
|
-
startQuote: string;
|
|
23
|
-
value: string;
|
|
24
|
-
endQuote: string;
|
|
25
|
-
afterAttr: string;
|
|
26
|
-
};
|
|
27
|
-
export {};
|