@markuplint/mustache-parser 3.6.0 → 3.6.2
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/parse.js +2 -2
- package/package.json +4 -4
- package/test/index.spec.js +91 -0
package/lib/parse.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parse = void 0;
|
|
4
4
|
const html_parser_1 = require("@markuplint/html-parser");
|
|
5
5
|
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
6
|
-
const parse = rawCode => {
|
|
6
|
+
const parse = (rawCode, options) => {
|
|
7
7
|
const blocks = (0, parser_utils_1.ignoreBlock)(rawCode, [
|
|
8
8
|
{
|
|
9
9
|
type: 'mustache-comment',
|
|
@@ -21,7 +21,7 @@ const parse = rawCode => {
|
|
|
21
21
|
end: /}}/,
|
|
22
22
|
},
|
|
23
23
|
]);
|
|
24
|
-
const doc = (0, html_parser_1.parse)(blocks.replaced);
|
|
24
|
+
const doc = (0, html_parser_1.parse)(blocks.replaced, options);
|
|
25
25
|
doc.nodeList = (0, parser_utils_1.restoreNode)(doc.nodeList, blocks);
|
|
26
26
|
return doc;
|
|
27
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/mustache-parser",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"description": "The mustache template parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"clean": "tsc --build --clean"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@markuplint/html-parser": "3.
|
|
19
|
+
"@markuplint/html-parser": "3.7.0",
|
|
20
20
|
"@markuplint/ml-ast": "3.1.0",
|
|
21
|
-
"@markuplint/parser-utils": "3.
|
|
21
|
+
"@markuplint/parser-utils": "3.7.0",
|
|
22
22
|
"tslib": "^2.4.1"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "adc6e432cccba7cfad0dc8bf9f92e5aaf1107359"
|
|
25
25
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const { nodeListToDebugMaps } = require('@markuplint/parser-utils');
|
|
2
|
+
|
|
3
|
+
const { parse } = require('../lib/');
|
|
4
|
+
|
|
5
|
+
describe('Node list', () => {
|
|
6
|
+
it('a code', () => {
|
|
7
|
+
const doc = parse('<div>abc{{ efg }}hij</div>');
|
|
8
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
9
|
+
'[1:1]>[1:6](0,5)div: <div>',
|
|
10
|
+
'[1:6]>[1:9](5,8)#text: abc',
|
|
11
|
+
'[1:9]>[1:18](8,17)#ps:mustache-tag: {{␣efg␣}}',
|
|
12
|
+
'[1:18]>[1:21](17,20)#text: hij',
|
|
13
|
+
'[1:21]>[1:27](20,26)div: </div>',
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('two codes', () => {
|
|
18
|
+
const doc = parse('<div>abc{{ efg }}hij{{ klm }}</div>');
|
|
19
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
20
|
+
'[1:1]>[1:6](0,5)div: <div>',
|
|
21
|
+
'[1:6]>[1:9](5,8)#text: abc',
|
|
22
|
+
'[1:9]>[1:18](8,17)#ps:mustache-tag: {{␣efg␣}}',
|
|
23
|
+
'[1:18]>[1:21](17,20)#text: hij',
|
|
24
|
+
'[1:21]>[1:30](20,29)#ps:mustache-tag: {{␣klm␣}}',
|
|
25
|
+
'[1:30]>[1:36](29,35)div: </div>',
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('two codes2', () => {
|
|
30
|
+
const doc = parse('<div>abc{{ efg }}hij{{ klm }}nop</div>');
|
|
31
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
32
|
+
'[1:1]>[1:6](0,5)div: <div>',
|
|
33
|
+
'[1:6]>[1:9](5,8)#text: abc',
|
|
34
|
+
'[1:9]>[1:18](8,17)#ps:mustache-tag: {{␣efg␣}}',
|
|
35
|
+
'[1:18]>[1:21](17,20)#text: hij',
|
|
36
|
+
'[1:21]>[1:30](20,29)#ps:mustache-tag: {{␣klm␣}}',
|
|
37
|
+
'[1:30]>[1:33](29,32)#text: nop',
|
|
38
|
+
'[1:33]>[1:39](32,38)div: </div>',
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('two codes2 on bare', () => {
|
|
43
|
+
const doc = parse('abc{{ efg }}hij{{ klm }}nop');
|
|
44
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
45
|
+
'[1:1]>[1:4](0,3)#text: abc',
|
|
46
|
+
'[1:4]>[1:13](3,12)#ps:mustache-tag: {{␣efg␣}}',
|
|
47
|
+
'[1:13]>[1:16](12,15)#text: hij',
|
|
48
|
+
'[1:16]>[1:25](15,24)#ps:mustache-tag: {{␣klm␣}}',
|
|
49
|
+
'[1:25]>[1:28](24,27)#text: nop',
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('nest block', () => {
|
|
54
|
+
const doc = parse('{{#nest}}abcdef{{/nest}}');
|
|
55
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
56
|
+
'[1:1]>[1:10](0,9)#ps:mustache-tag: {{#nest}}',
|
|
57
|
+
'[1:10]>[1:16](9,15)#text: abcdef',
|
|
58
|
+
'[1:16]>[1:25](15,24)#ps:mustache-tag: {{/nest}}',
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('nest block', () => {
|
|
63
|
+
const doc = parse('{{#user}}<div>{{ user.name }}</div>{{/user}}');
|
|
64
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
65
|
+
'[1:1]>[1:10](0,9)#ps:mustache-tag: {{#user}}',
|
|
66
|
+
'[1:10]>[1:15](9,14)div: <div>',
|
|
67
|
+
'[1:15]>[1:30](14,29)#ps:mustache-tag: {{␣user.name␣}}',
|
|
68
|
+
'[1:30]>[1:36](29,35)div: </div>',
|
|
69
|
+
'[1:36]>[1:45](35,44)#ps:mustache-tag: {{/user}}',
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const el = doc.nodeList[2];
|
|
73
|
+
const el2 = doc.nodeList[2].parentNode.childNodes[0];
|
|
74
|
+
expect(el.nodeName).toBe(el2.nodeName);
|
|
75
|
+
expect(el.uuid).toBe(el2.uuid);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('Tags', () => {
|
|
80
|
+
it('mustache-tag', () => {
|
|
81
|
+
expect(parse('{{ any }}').nodeList[0].nodeName).toBe('#ps:mustache-tag');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('mustache-unescaped', () => {
|
|
85
|
+
expect(parse('{{{ any }}}').nodeList[0].nodeName).toBe('#ps:mustache-unescaped');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('mustache-comment', () => {
|
|
89
|
+
expect(parse('{{! any }}').nodeList[0].nodeName).toBe('#ps:mustache-comment');
|
|
90
|
+
});
|
|
91
|
+
});
|