@markuplint/html-parser 3.3.1 → 3.4.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 +6 -5
- package/lib/flatten-nodes.js +1 -1
- package/lib/get-namespace.js +1 -1
- package/lib/parse-raw-tag.js +5 -4
- package/package.json +3 -3
package/lib/attr-tokenizer.js
CHANGED
|
@@ -5,17 +5,18 @@ 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
9
|
const attrMatchedMap = raw.match(reAttrsInStartTag);
|
|
9
10
|
if (!attrMatchedMap) {
|
|
10
11
|
throw new SyntaxError('Illegal attribute token');
|
|
11
12
|
}
|
|
12
|
-
const spacesBeforeAttrString = attrMatchedMap[1];
|
|
13
|
-
const nameChars = attrMatchedMap[2];
|
|
14
|
-
const spacesBeforeEqualChars = attrMatchedMap[3]
|
|
13
|
+
const spacesBeforeAttrString = (_a = attrMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
|
|
14
|
+
const nameChars = (_b = attrMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
|
|
15
|
+
const spacesBeforeEqualChars = (_c = attrMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
|
|
15
16
|
const equalChars = attrMatchedMap[4] || null;
|
|
16
|
-
const spacesAfterEqualChars = attrMatchedMap[5]
|
|
17
|
+
const spacesAfterEqualChars = (_d = attrMatchedMap[5]) !== null && _d !== void 0 ? _d : '';
|
|
17
18
|
const quoteChars = attrMatchedMap[6] != null ? '"' : attrMatchedMap[7] != null ? "'" : null;
|
|
18
|
-
const valueChars = attrMatchedMap[6]
|
|
19
|
+
const valueChars = (_g = (_f = (_e = attrMatchedMap[6]) !== null && _e !== void 0 ? _e : attrMatchedMap[7]) !== null && _f !== void 0 ? _f : attrMatchedMap[8]) !== null && _g !== void 0 ? _g : (quoteChars ? '' : null);
|
|
19
20
|
let offset = startOffset;
|
|
20
21
|
const spacesBeforeName = (0, parser_utils_1.tokenizer)(spacesBeforeAttrString, line, col, offset);
|
|
21
22
|
line = spacesBeforeName.endLine;
|
package/lib/flatten-nodes.js
CHANGED
|
@@ -26,7 +26,7 @@ function flattenNodes(nodeTree, rawHtml, createLastText = true) {
|
|
|
26
26
|
const prevWreckagesText = prevToken;
|
|
27
27
|
if (prevWreckagesText) {
|
|
28
28
|
const wreckages = (0, tag_splitter_1.default)(prevWreckagesText.raw, prevWreckagesText.startLine, prevWreckagesText.startCol);
|
|
29
|
-
if (wreckages.length) {
|
|
29
|
+
if (wreckages.length && wreckages[0]) {
|
|
30
30
|
// console.log('wreckages\n', wreckages);
|
|
31
31
|
const lastText = wreckages[0];
|
|
32
32
|
const raw = lastText.raw;
|
package/lib/get-namespace.js
CHANGED
|
@@ -27,7 +27,7 @@ function getNamespace(tagName, parentNamespace = DEFAULT_NAMESPACE) {
|
|
|
27
27
|
const doc = (0, parse5_1.parse)(tag);
|
|
28
28
|
node = doc.childNodes[0];
|
|
29
29
|
}
|
|
30
|
-
if ('namespaceURI' in node) {
|
|
30
|
+
if (node && 'namespaceURI' in node) {
|
|
31
31
|
return node.namespaceURI;
|
|
32
32
|
}
|
|
33
33
|
return DEFAULT_NAMESPACE;
|
package/lib/parse-raw-tag.js
CHANGED
|
@@ -8,14 +8,15 @@ const const_1 = require("./const");
|
|
|
8
8
|
const reAttrsInStartTag = /\s*[^\x00-\x1f\x7f-\x9f "'>/=]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^\s]*))?/;
|
|
9
9
|
const reEndTokens = /(\s*\/)?(\s*)>$/;
|
|
10
10
|
function parseRawTag(raw, startLine, startCol, startOffset, offsetOffset = 0, offsetLine = 0, offsetColumn = 0) {
|
|
11
|
+
var _a, _b;
|
|
11
12
|
let offset = startOffset + offsetOffset;
|
|
12
13
|
let line = startLine + offsetLine;
|
|
13
14
|
let col = startCol + (startLine === 1 ? offsetColumn : 0);
|
|
14
15
|
const matches = raw.match(const_1.reTag);
|
|
15
|
-
|
|
16
|
+
const tagWithAttrs = matches === null || matches === void 0 ? void 0 : matches[1];
|
|
17
|
+
if (!tagWithAttrs) {
|
|
16
18
|
throw new SyntaxError(`Invalid tag syntax: "${raw}"`);
|
|
17
19
|
}
|
|
18
|
-
const tagWithAttrs = matches[1];
|
|
19
20
|
// eslint-disable-next-line no-control-regex
|
|
20
21
|
const tagNameSplitted = tagWithAttrs.split(/[\u0000\u0009\u000A\u000C\u0020/>]/);
|
|
21
22
|
const tagName = tagNameSplitted[0] || tagNameSplitted[1];
|
|
@@ -41,11 +42,11 @@ function parseRawTag(raw, startLine, startCol, startOffset, offsetOffset = 0, of
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
const endTokens = reEndTokens.exec(raw);
|
|
44
|
-
const selfClosingSolidus = (0, parser_utils_1.tokenizer)(endTokens
|
|
45
|
+
const selfClosingSolidus = (0, parser_utils_1.tokenizer)((_a = endTokens === null || endTokens === void 0 ? void 0 : endTokens[1]) !== null && _a !== void 0 ? _a : '', line, col, offset);
|
|
45
46
|
line = selfClosingSolidus.endLine;
|
|
46
47
|
col = selfClosingSolidus.endCol;
|
|
47
48
|
offset = selfClosingSolidus.endOffset;
|
|
48
|
-
const endSpace = (0, parser_utils_1.tokenizer)(endTokens
|
|
49
|
+
const endSpace = (0, parser_utils_1.tokenizer)((_b = endTokens === null || endTokens === void 0 ? void 0 : endTokens[2]) !== null && _b !== void 0 ? _b : '', line, col, offset);
|
|
49
50
|
return {
|
|
50
51
|
tagName,
|
|
51
52
|
attrs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/html-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@markuplint/ml-ast": "3.0.0",
|
|
24
|
-
"@markuplint/parser-utils": "3.
|
|
24
|
+
"@markuplint/parser-utils": "3.4.0",
|
|
25
25
|
"parse5": "7.1.2",
|
|
26
26
|
"tslib": "^2.4.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
|
|
29
29
|
}
|