@markuplint/parser-utils 1.6.1 → 2.0.0-dev.23
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/lib/const.d.ts +6 -0
- package/lib/const.js +96 -1
- package/lib/create-token.d.ts +4 -0
- package/lib/create-token.js +35 -0
- package/lib/debugger.d.ts +3 -0
- package/lib/debugger.js +57 -0
- package/lib/decision.d.ts +29 -0
- package/lib/decision.js +51 -0
- package/lib/get-location.d.ts +13 -0
- package/lib/get-location.js +36 -0
- package/lib/idl-attributes.d.ts +4 -0
- package/lib/idl-attributes.js +405 -0
- package/lib/idl-attributes.test.d.ts +1 -0
- package/lib/idl-attributes.test.js +45 -0
- package/lib/ignore-block.d.ts +2 -2
- package/lib/ignore-block.js +85 -34
- package/lib/ignore-front-matter.d.ts +1 -0
- package/lib/ignore-front-matter.js +21 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +8 -21
- package/lib/siblings-correction.d.ts +9 -0
- package/lib/siblings-correction.js +20 -0
- package/lib/walker.d.ts +2 -0
- package/lib/walker.js +20 -0
- package/package.json +4 -4
- package/tsconfig.test.json +1 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/utils.d.ts +0 -52
- package/lib/utils.js +0 -191
package/lib/const.d.ts
CHANGED
package/lib/const.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rePCEN = exports.MASK_CHAR = void 0;
|
|
3
|
+
exports.svgElementList = exports.rePCEN = exports.MASK_CHAR = void 0;
|
|
4
4
|
exports.MASK_CHAR = '\uE000';
|
|
5
5
|
/**
|
|
6
6
|
* PotentialCustomElementName
|
|
@@ -38,3 +38,98 @@ const rePCENChar = [
|
|
|
38
38
|
'[\uD800-\uDBFF][\uDC00-\uDFFF]',
|
|
39
39
|
].join('|');
|
|
40
40
|
exports.rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i');
|
|
41
|
+
/**
|
|
42
|
+
* SVG Element list
|
|
43
|
+
*
|
|
44
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element
|
|
45
|
+
*/
|
|
46
|
+
exports.svgElementList = [
|
|
47
|
+
'a',
|
|
48
|
+
'animate',
|
|
49
|
+
'animateMotion',
|
|
50
|
+
'animateTransform',
|
|
51
|
+
'circle',
|
|
52
|
+
'clipPath',
|
|
53
|
+
'defs',
|
|
54
|
+
'desc',
|
|
55
|
+
'discard',
|
|
56
|
+
'ellipse',
|
|
57
|
+
'feBlend',
|
|
58
|
+
'feColorMatrix',
|
|
59
|
+
'feComponentTransfer',
|
|
60
|
+
'feComposite',
|
|
61
|
+
'feConvolveMatrix',
|
|
62
|
+
'feDiffuseLighting',
|
|
63
|
+
'feDisplacementMap',
|
|
64
|
+
'feDistantLight',
|
|
65
|
+
'feDropShadow',
|
|
66
|
+
'feFlood',
|
|
67
|
+
'feFuncA',
|
|
68
|
+
'feFuncB',
|
|
69
|
+
'feFuncG',
|
|
70
|
+
'feFuncR',
|
|
71
|
+
'feGaussianBlur',
|
|
72
|
+
'feImage',
|
|
73
|
+
'feMerge',
|
|
74
|
+
'feMergeNode',
|
|
75
|
+
'feMorphology',
|
|
76
|
+
'feOffset',
|
|
77
|
+
'fePointLight',
|
|
78
|
+
'feSpecularLighting',
|
|
79
|
+
'feSpotLight',
|
|
80
|
+
'feTile',
|
|
81
|
+
'feTurbulence',
|
|
82
|
+
'filter',
|
|
83
|
+
'foreignObject',
|
|
84
|
+
'g',
|
|
85
|
+
'hatch',
|
|
86
|
+
'hatchpath',
|
|
87
|
+
'image',
|
|
88
|
+
'line',
|
|
89
|
+
'linearGradient',
|
|
90
|
+
'marker',
|
|
91
|
+
'mask',
|
|
92
|
+
'mesh',
|
|
93
|
+
'meshgradient',
|
|
94
|
+
'meshpatch',
|
|
95
|
+
'meshrow',
|
|
96
|
+
'metadata',
|
|
97
|
+
'mpath',
|
|
98
|
+
'path',
|
|
99
|
+
'pattern',
|
|
100
|
+
'polygon',
|
|
101
|
+
'polyline',
|
|
102
|
+
'radialGradient',
|
|
103
|
+
'rect',
|
|
104
|
+
'script',
|
|
105
|
+
'set',
|
|
106
|
+
'stop',
|
|
107
|
+
'style',
|
|
108
|
+
'svg',
|
|
109
|
+
'switch',
|
|
110
|
+
'symbol',
|
|
111
|
+
'text',
|
|
112
|
+
'textPath',
|
|
113
|
+
'title',
|
|
114
|
+
'tspan',
|
|
115
|
+
'use',
|
|
116
|
+
'view',
|
|
117
|
+
// Below: Obsolete and deprecated elements
|
|
118
|
+
'altGlyph',
|
|
119
|
+
'altGlyphDef',
|
|
120
|
+
'altGlyphItem',
|
|
121
|
+
'animateColor',
|
|
122
|
+
'cursor',
|
|
123
|
+
'font',
|
|
124
|
+
'font-face',
|
|
125
|
+
'font-face-format',
|
|
126
|
+
'font-face-name',
|
|
127
|
+
'font-face-src',
|
|
128
|
+
'font-face-uri',
|
|
129
|
+
'glyph',
|
|
130
|
+
'glyphRef',
|
|
131
|
+
'hkern',
|
|
132
|
+
'missing-glyph',
|
|
133
|
+
'tref',
|
|
134
|
+
'vkern',
|
|
135
|
+
];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MLToken } from '@markuplint/ml-ast';
|
|
2
|
+
export declare function tokenizer(raw: string | null, startLine: number, startCol: number, startOffset: number): MLToken;
|
|
3
|
+
export declare function createTokenFromRawCode(raw: string | null, startOffset: number, rawCode: string): MLToken;
|
|
4
|
+
export declare function uuid(): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 || '';
|
|
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 || '';
|
|
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/debugger.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attributesToDebugMaps = exports.nodeListToDebugMaps = void 0;
|
|
4
|
+
function nodeListToDebugMaps(nodeList, withAttr = false) {
|
|
5
|
+
return nodeList
|
|
6
|
+
.map(n => {
|
|
7
|
+
const r = [];
|
|
8
|
+
if (!n.isGhost) {
|
|
9
|
+
r.push(tokenDebug(n));
|
|
10
|
+
if (withAttr && 'attributes' in n) {
|
|
11
|
+
r.push(...attributesToDebugMaps(n.attributes).flat());
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
r.push(`[N/A]>[N/A](N/A)${n.nodeName}: ${visibleWhiteSpace(n.raw)}`);
|
|
16
|
+
}
|
|
17
|
+
return r;
|
|
18
|
+
})
|
|
19
|
+
.flat();
|
|
20
|
+
}
|
|
21
|
+
exports.nodeListToDebugMaps = nodeListToDebugMaps;
|
|
22
|
+
function attributesToDebugMaps(attributes) {
|
|
23
|
+
return attributes.map(n => {
|
|
24
|
+
const r = [
|
|
25
|
+
tokenDebug({
|
|
26
|
+
...n,
|
|
27
|
+
name: n.type === 'html-attr' ? n.name.raw : n.raw,
|
|
28
|
+
}),
|
|
29
|
+
];
|
|
30
|
+
if (n.type === 'html-attr') {
|
|
31
|
+
r.push(` ${tokenDebug(n.spacesBeforeName, 'bN')}`);
|
|
32
|
+
r.push(` ${tokenDebug(n.name, 'name')}`);
|
|
33
|
+
r.push(` ${tokenDebug(n.spacesBeforeEqual, 'bE')}`);
|
|
34
|
+
r.push(` ${tokenDebug(n.equal, 'equal')}`);
|
|
35
|
+
r.push(` ${tokenDebug(n.spacesAfterEqual, 'aE')}`);
|
|
36
|
+
r.push(` ${tokenDebug(n.startQuote, 'sQ')}`);
|
|
37
|
+
r.push(` ${tokenDebug(n.value, 'value')}`);
|
|
38
|
+
r.push(` ${tokenDebug(n.endQuote, 'eQ')}`);
|
|
39
|
+
r.push(` isDirective: ${!!n.isDirective}`);
|
|
40
|
+
r.push(` isDynamicValue: ${!!n.isDynamicValue}`);
|
|
41
|
+
}
|
|
42
|
+
if (n.potentialName != null) {
|
|
43
|
+
r.push(` potentialName: ${visibleWhiteSpace(n.potentialName)}`);
|
|
44
|
+
}
|
|
45
|
+
if (n.type === 'html-attr' && n.candidate) {
|
|
46
|
+
r.push(` candidate: ${visibleWhiteSpace(n.candidate)}`);
|
|
47
|
+
}
|
|
48
|
+
return r;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.attributesToDebugMaps = attributesToDebugMaps;
|
|
52
|
+
function tokenDebug(n, type = '') {
|
|
53
|
+
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)}`;
|
|
54
|
+
}
|
|
55
|
+
function visibleWhiteSpace(chars) {
|
|
56
|
+
return chars.replace(/\n/g, '⏎').replace(/\t/g, '→').replace(/\s/g, '␣');
|
|
57
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*
|
|
4
|
+
* @param nodeName
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSVGElement(nodeName: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* valid name of custom element
|
|
10
|
+
*
|
|
11
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
12
|
+
*
|
|
13
|
+
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
14
|
+
* > - name must not be any of the following:
|
|
15
|
+
* > - `<annotation-xml>`
|
|
16
|
+
* > - `<color-profile>`
|
|
17
|
+
* > - `<font-face>`
|
|
18
|
+
* > - `<font-face-src>`
|
|
19
|
+
* > - `<font-face-uri>`
|
|
20
|
+
* > - `<font-face-format>`
|
|
21
|
+
* > - `<font-face-name>`
|
|
22
|
+
* > - `<missing-glyph>`
|
|
23
|
+
*
|
|
24
|
+
* ASCII-case-insensitively.
|
|
25
|
+
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
26
|
+
*
|
|
27
|
+
* @param tagName
|
|
28
|
+
*/
|
|
29
|
+
export declare function isPotentialCustomElementName(tagName: string): boolean;
|
package/lib/decision.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPotentialCustomElementName = exports.isSVGElement = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @param nodeName
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function isSVGElement(nodeName) {
|
|
12
|
+
return const_1.svgElementList.includes(nodeName);
|
|
13
|
+
}
|
|
14
|
+
exports.isSVGElement = isSVGElement;
|
|
15
|
+
/**
|
|
16
|
+
* valid name of custom element
|
|
17
|
+
*
|
|
18
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
19
|
+
*
|
|
20
|
+
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
21
|
+
* > - name must not be any of the following:
|
|
22
|
+
* > - `<annotation-xml>`
|
|
23
|
+
* > - `<color-profile>`
|
|
24
|
+
* > - `<font-face>`
|
|
25
|
+
* > - `<font-face-src>`
|
|
26
|
+
* > - `<font-face-uri>`
|
|
27
|
+
* > - `<font-face-format>`
|
|
28
|
+
* > - `<font-face-name>`
|
|
29
|
+
* > - `<missing-glyph>`
|
|
30
|
+
*
|
|
31
|
+
* ASCII-case-insensitively.
|
|
32
|
+
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
33
|
+
*
|
|
34
|
+
* @param tagName
|
|
35
|
+
*/
|
|
36
|
+
function isPotentialCustomElementName(tagName) {
|
|
37
|
+
switch (tagName) {
|
|
38
|
+
case 'annotation-xml':
|
|
39
|
+
case 'color-profile':
|
|
40
|
+
case 'font-face':
|
|
41
|
+
case 'font-face-src':
|
|
42
|
+
case 'font-face-uri':
|
|
43
|
+
case 'font-face-format':
|
|
44
|
+
case 'font-face-name':
|
|
45
|
+
case 'missing-glyph': {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return const_1.rePCEN.test(tagName);
|
|
50
|
+
}
|
|
51
|
+
exports.isPotentialCustomElementName = isPotentialCustomElementName;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function getLine(html: string, startOffset: number): number;
|
|
2
|
+
export declare function getCol(html: string, startOffset: number): number;
|
|
3
|
+
export declare function getEndLine(html: string, line: number): number;
|
|
4
|
+
export declare function getEndCol(html: string, col: number): number;
|
|
5
|
+
export declare function sliceFragment(rawHtml: string, start: number, end: number): {
|
|
6
|
+
startOffset: number;
|
|
7
|
+
endOffset: number;
|
|
8
|
+
startLine: number;
|
|
9
|
+
endLine: number;
|
|
10
|
+
startCol: number;
|
|
11
|
+
endCol: number;
|
|
12
|
+
raw: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sliceFragment = exports.getEndCol = exports.getEndLine = exports.getCol = exports.getLine = void 0;
|
|
4
|
+
function getLine(html, startOffset) {
|
|
5
|
+
return html.slice(0, startOffset).split(/\n/g).length;
|
|
6
|
+
}
|
|
7
|
+
exports.getLine = getLine;
|
|
8
|
+
function getCol(html, startOffset) {
|
|
9
|
+
const lines = html.slice(0, startOffset).split(/\n/g);
|
|
10
|
+
return lines[lines.length - 1].length + 1;
|
|
11
|
+
}
|
|
12
|
+
exports.getCol = getCol;
|
|
13
|
+
function getEndLine(html, line) {
|
|
14
|
+
return html.split(/\r?\n/).length - 1 + line;
|
|
15
|
+
}
|
|
16
|
+
exports.getEndLine = getEndLine;
|
|
17
|
+
function getEndCol(html, col) {
|
|
18
|
+
const lines = html.split(/\r?\n/);
|
|
19
|
+
const lineCount = lines.length;
|
|
20
|
+
const lastLine = lines.pop();
|
|
21
|
+
return lineCount > 1 ? lastLine.length + 1 : col + html.length;
|
|
22
|
+
}
|
|
23
|
+
exports.getEndCol = getEndCol;
|
|
24
|
+
function sliceFragment(rawHtml, start, end) {
|
|
25
|
+
const raw = rawHtml.slice(start, end);
|
|
26
|
+
return {
|
|
27
|
+
startOffset: start,
|
|
28
|
+
endOffset: end,
|
|
29
|
+
startLine: getLine(rawHtml, start),
|
|
30
|
+
endLine: getLine(rawHtml, end),
|
|
31
|
+
startCol: getCol(rawHtml, start),
|
|
32
|
+
endCol: getCol(rawHtml, end),
|
|
33
|
+
raw,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.sliceFragment = sliceFragment;
|