@markuplint/html-parser 3.5.0 → 3.6.0
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/attr-tokenizer.js
CHANGED
|
@@ -5,7 +5,7 @@ const reAttrsInStartTag =
|
|
|
5
5
|
// eslint-disable-next-line no-control-regex
|
|
6
6
|
/(\s*)([^\x00-\x1f\x7f-\x9f "'>/=]+)(?:(\s*)(=)(\s*)(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s]*)))?/;
|
|
7
7
|
function attrTokenizer(raw, line, col, startOffset) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9
9
|
const attrMatchedMap = raw.match(reAttrsInStartTag);
|
|
10
10
|
if (!attrMatchedMap) {
|
|
11
11
|
throw new SyntaxError('Illegal attribute token');
|
|
@@ -13,10 +13,10 @@ function attrTokenizer(raw, line, col, startOffset) {
|
|
|
13
13
|
const spacesBeforeAttrString = (_a = attrMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
|
|
14
14
|
const nameChars = (_b = attrMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
|
|
15
15
|
const spacesBeforeEqualChars = (_c = attrMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
|
|
16
|
-
const equalChars = attrMatchedMap[4]
|
|
17
|
-
const spacesAfterEqualChars = (
|
|
16
|
+
const equalChars = (_d = attrMatchedMap[4]) !== null && _d !== void 0 ? _d : null;
|
|
17
|
+
const spacesAfterEqualChars = (_e = attrMatchedMap[5]) !== null && _e !== void 0 ? _e : '';
|
|
18
18
|
const quoteChars = attrMatchedMap[6] != null ? '"' : attrMatchedMap[7] != null ? "'" : null;
|
|
19
|
-
const valueChars = (
|
|
19
|
+
const valueChars = (_h = (_g = (_f = attrMatchedMap[6]) !== null && _f !== void 0 ? _f : attrMatchedMap[7]) !== null && _g !== void 0 ? _g : attrMatchedMap[8]) !== null && _h !== void 0 ? _h : (quoteChars ? '' : null);
|
|
20
20
|
let offset = startOffset;
|
|
21
21
|
const spacesBeforeName = (0, parser_utils_1.tokenizer)(spacesBeforeAttrString, line, col, offset);
|
|
22
22
|
line = spacesBeforeName.endLine;
|
|
@@ -49,11 +49,11 @@ function attrTokenizer(raw, line, col, startOffset) {
|
|
|
49
49
|
const endQuote = (0, parser_utils_1.tokenizer)(quoteChars, line, col, offset);
|
|
50
50
|
const attrToken = (0, parser_utils_1.tokenizer)(nameChars +
|
|
51
51
|
spacesBeforeEqualChars +
|
|
52
|
-
(equalChars
|
|
52
|
+
(equalChars !== null && equalChars !== void 0 ? equalChars : '') +
|
|
53
53
|
spacesAfterEqualChars +
|
|
54
|
-
(quoteChars
|
|
55
|
-
(valueChars
|
|
56
|
-
(quoteChars
|
|
54
|
+
(quoteChars !== null && quoteChars !== void 0 ? quoteChars : '') +
|
|
55
|
+
(valueChars !== null && valueChars !== void 0 ? valueChars : '') +
|
|
56
|
+
(quoteChars !== null && quoteChars !== void 0 ? quoteChars : ''), name.startLine, name.startCol, name.startOffset);
|
|
57
57
|
return {
|
|
58
58
|
type: 'html-attr',
|
|
59
59
|
uuid: (0, parser_utils_1.uuid)(),
|
package/lib/create-tree.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
2
|
-
export declare function createTree(
|
|
2
|
+
export declare function createTree(
|
|
3
|
+
rawCode: string,
|
|
4
|
+
isFragment: boolean,
|
|
5
|
+
offsetOffset: number,
|
|
6
|
+
offsetLine: number,
|
|
7
|
+
offsetColumn: number,
|
|
8
|
+
): MLASTNode[];
|
package/lib/create-tree.js
CHANGED
|
@@ -41,10 +41,11 @@ function nodeize(originNode,
|
|
|
41
41
|
prevNode,
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
43
|
parentNode, rawHtml, offsetOffset, offsetLine, offsetColumn) {
|
|
44
|
+
var _a, _b, _c;
|
|
44
45
|
const nextNode = null;
|
|
45
46
|
const location = getLocation(originNode);
|
|
46
47
|
if (!location) {
|
|
47
|
-
const prevToken = prevNode
|
|
48
|
+
const prevToken = prevNode !== null && prevNode !== void 0 ? prevNode : parentNode;
|
|
48
49
|
const startOffset = prevToken ? prevToken.endOffset : 0;
|
|
49
50
|
const endOffset = prevToken ? prevToken.endOffset : 0;
|
|
50
51
|
const startLine = prevToken ? prevToken.endLine : 0;
|
|
@@ -79,18 +80,18 @@ parentNode, rawHtml, offsetOffset, offsetLine, offsetColumn) {
|
|
|
79
80
|
return node;
|
|
80
81
|
}
|
|
81
82
|
const { startOffset, endOffset, startLine, endLine, startCol, endCol } = location;
|
|
82
|
-
const raw = rawHtml.slice(startOffset, endOffset
|
|
83
|
+
const raw = rawHtml.slice(startOffset, endOffset !== null && endOffset !== void 0 ? endOffset : startOffset);
|
|
83
84
|
switch (originNode.nodeName) {
|
|
84
85
|
case '#documentType': {
|
|
85
86
|
return {
|
|
86
87
|
uuid: (0, parser_utils_1.uuid)(),
|
|
87
88
|
raw,
|
|
88
89
|
// @ts-ignore
|
|
89
|
-
name: originNode.name
|
|
90
|
+
name: (_a = originNode.name) !== null && _a !== void 0 ? _a : '',
|
|
90
91
|
// @ts-ignore
|
|
91
|
-
publicId: originNode.publicId
|
|
92
|
+
publicId: (_b = originNode.publicId) !== null && _b !== void 0 ? _b : '',
|
|
92
93
|
// @ts-ignore
|
|
93
|
-
systemId: originNode.systemId
|
|
94
|
+
systemId: (_c = originNode.systemId) !== null && _c !== void 0 ? _c : '',
|
|
94
95
|
startOffset: startOffset + offsetOffset,
|
|
95
96
|
endOffset: endOffset + offsetOffset,
|
|
96
97
|
startLine: startLine + offsetLine,
|
|
@@ -150,7 +151,7 @@ parentNode, rawHtml, offsetOffset, offsetLine, offsetColumn) {
|
|
|
150
151
|
const tagLoc = 'startTag' in location ? location.startTag : null;
|
|
151
152
|
const startTagRaw = tagLoc
|
|
152
153
|
? rawHtml.slice(tagLoc.startOffset, tagLoc.endOffset)
|
|
153
|
-
: rawHtml.slice(startOffset, endOffset
|
|
154
|
+
: rawHtml.slice(startOffset, endOffset !== null && endOffset !== void 0 ? endOffset : startOffset);
|
|
154
155
|
const tagTokens = (0, parse_raw_tag_1.default)(startTagRaw, startLine, startCol, startOffset, offsetOffset, offsetLine, offsetColumn);
|
|
155
156
|
const tagName = tagTokens.tagName;
|
|
156
157
|
let endTag = null;
|
|
@@ -240,7 +241,8 @@ parentNode, rawHtml, offsetOffset, offsetLine, offsetColumn) {
|
|
|
240
241
|
* - If node has "content" property then parse as document fragment.
|
|
241
242
|
*/
|
|
242
243
|
function getChildNodes(rootNode) {
|
|
243
|
-
|
|
244
|
+
var _a;
|
|
245
|
+
return rootNode.content ? rootNode.content.childNodes : (_a = rootNode.childNodes) !== null && _a !== void 0 ? _a : [];
|
|
244
246
|
}
|
|
245
247
|
function hasLocation(node) {
|
|
246
248
|
return 'sourceCodeLocation' in node;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
2
2
|
export declare function isStartsHeadTagOrBodyTag(rawCode: string): boolean;
|
|
3
3
|
export declare function optimizeStartsHeadTagOrBodyTagSetup(rawCode: string): {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
code: string;
|
|
5
|
+
heads: string[];
|
|
6
|
+
bodies: string[];
|
|
7
7
|
};
|
|
8
|
-
export declare function optimizeStartsHeadTagOrBodyTagResume(
|
|
8
|
+
export declare function optimizeStartsHeadTagOrBodyTagResume(
|
|
9
|
+
nodeList: MLASTNode[],
|
|
10
|
+
replacements: ReturnType<typeof optimizeStartsHeadTagOrBodyTagSetup>,
|
|
11
|
+
): void;
|
package/lib/parse-raw-tag.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { MLASTAttr, MLToken } from '@markuplint/ml-ast';
|
|
2
2
|
type TagTokens = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
tagName: string;
|
|
4
|
+
attrs: MLASTAttr[];
|
|
5
|
+
selfClosingSolidus: MLToken;
|
|
6
|
+
endSpace: MLToken;
|
|
7
7
|
};
|
|
8
|
-
export default function parseRawTag(
|
|
8
|
+
export default function parseRawTag(
|
|
9
|
+
raw: string,
|
|
10
|
+
startLine: number,
|
|
11
|
+
startCol: number,
|
|
12
|
+
startOffset: number,
|
|
13
|
+
offsetOffset?: number,
|
|
14
|
+
offsetLine?: number,
|
|
15
|
+
offsetColumn?: number,
|
|
16
|
+
): TagTokens;
|
|
9
17
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/html-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "HTML parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@markuplint/ml-ast": "3.1.0",
|
|
24
|
-
"@markuplint/parser-utils": "3.
|
|
24
|
+
"@markuplint/parser-utils": "3.6.0",
|
|
25
25
|
"parse5": "7.1.2",
|
|
26
26
|
"tslib": "^2.4.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"type-fest": "^3.7.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
|
|
32
32
|
}
|