@markuplint/smarty-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 +155 -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: 'smarty-literal',
|
|
@@ -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/smarty-parser",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"description": "Smarty parser for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -16,9 +16,9 @@
|
|
|
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
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "adc6e432cccba7cfad0dc8bf9f92e5aaf1107359"
|
|
24
24
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
|
|
12
|
+
'[1:16]>[1:19](15,18)#text: hij',
|
|
13
|
+
'[1:19]>[1:25](18,24)div: </div>',
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('two codes', () => {
|
|
18
|
+
const doc = parse('<div>abc{ efg }hij{ kim }</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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
|
|
23
|
+
'[1:16]>[1:19](15,18)#text: hij',
|
|
24
|
+
'[1:19]>[1:26](18,25)#ps:smarty-scriptlet: {␣kim␣}',
|
|
25
|
+
'[1:26]>[1:32](25,31)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:16](8,15)#ps:smarty-scriptlet: {␣efg␣}',
|
|
35
|
+
'[1:16]>[1:19](15,18)#text: hij',
|
|
36
|
+
'[1:19]>[1:26](18,25)#ps:smarty-scriptlet: {␣klm␣}',
|
|
37
|
+
'[1:26]>[1:29](25,28)#text: nop',
|
|
38
|
+
'[1:29]>[1:35](28,34)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:11](3,10)#ps:smarty-scriptlet: {␣efg␣}',
|
|
47
|
+
'[1:11]>[1:14](10,13)#text: hij',
|
|
48
|
+
'[1:14]>[1:21](13,20)#ps:smarty-scriptlet: {␣klm␣}',
|
|
49
|
+
'[1:21]>[1:24](20,23)#text: nop',
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('nest block', () => {
|
|
54
|
+
const doc = parse('{if foo}abcdef{/if}');
|
|
55
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
56
|
+
'[1:1]>[1:9](0,8)#ps:smarty-scriptlet: {if␣foo}',
|
|
57
|
+
'[1:9]>[1:15](8,14)#text: abcdef',
|
|
58
|
+
'[1:15]>[1:20](14,19)#ps:smarty-scriptlet: {/if}',
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('nest block', () => {
|
|
63
|
+
const doc = parse('{if foo}abc{ foo }def{/if}');
|
|
64
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
65
|
+
'[1:1]>[1:9](0,8)#ps:smarty-scriptlet: {if␣foo}',
|
|
66
|
+
'[1:9]>[1:12](8,11)#text: abc',
|
|
67
|
+
'[1:12]>[1:19](11,18)#ps:smarty-scriptlet: {␣foo␣}',
|
|
68
|
+
'[1:19]>[1:22](18,21)#text: def',
|
|
69
|
+
'[1:22]>[1:27](21,26)#ps:smarty-scriptlet: {/if}',
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('nest block', () => {
|
|
74
|
+
const doc = parse(`{if user}
|
|
75
|
+
<div>{ user.name }</div>
|
|
76
|
+
{/if}
|
|
77
|
+
`);
|
|
78
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
79
|
+
'[1:1]>[1:10](0,9)#ps:smarty-scriptlet: {if␣user}',
|
|
80
|
+
'[1:10]>[2:1](9,10)#text: ⏎',
|
|
81
|
+
'[2:1]>[2:6](10,15)div: <div>',
|
|
82
|
+
'[2:6]>[2:19](15,28)#ps:smarty-scriptlet: {␣user.name␣}',
|
|
83
|
+
'[2:19]>[2:25](28,34)div: </div>',
|
|
84
|
+
'[2:25]>[3:1](34,35)#text: ⏎',
|
|
85
|
+
'[3:1]>[3:6](35,40)#ps:smarty-scriptlet: {/if}',
|
|
86
|
+
'[3:6]>[4:1](40,41)#text: ⏎',
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const el = doc.nodeList[3];
|
|
90
|
+
const el2 = doc.nodeList[3].parentNode.childNodes[0];
|
|
91
|
+
expect(el.nodeName).toBe(el2.nodeName);
|
|
92
|
+
expect(el.uuid).toBe(el2.uuid);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('Full HTML', () => {
|
|
96
|
+
const doc = parse(`<!DOCTYPE html>
|
|
97
|
+
<html lang="en">
|
|
98
|
+
<head>
|
|
99
|
+
{include file='path/to'}
|
|
100
|
+
<meta />
|
|
101
|
+
</head>
|
|
102
|
+
<body></body>
|
|
103
|
+
</html>
|
|
104
|
+
`);
|
|
105
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
106
|
+
'[1:1]>[1:16](0,15)#doctype: <!DOCTYPE␣html>',
|
|
107
|
+
'[1:16]>[2:1](15,16)#text: ⏎',
|
|
108
|
+
'[2:1]>[2:17](16,32)html: <html␣lang="en">',
|
|
109
|
+
'[2:17]>[3:2](32,34)#text: ⏎→',
|
|
110
|
+
'[3:2]>[3:8](34,40)head: <head>',
|
|
111
|
+
'[3:8]>[4:3](40,43)#text: ⏎→→',
|
|
112
|
+
"[4:3]>[4:27](43,67)#ps:smarty-scriptlet: {include␣file='path/to'}",
|
|
113
|
+
'[4:27]>[5:3](67,70)#text: ⏎→→',
|
|
114
|
+
'[5:3]>[5:11](70,78)meta: <meta␣/>',
|
|
115
|
+
'[5:11]>[6:2](78,80)#text: ⏎→',
|
|
116
|
+
'[6:2]>[6:9](80,87)head: </head>',
|
|
117
|
+
'[6:9]>[7:2](87,89)#text: ⏎→',
|
|
118
|
+
'[7:2]>[7:8](89,95)body: <body>',
|
|
119
|
+
'[7:8]>[7:15](95,102)body: </body>',
|
|
120
|
+
'[7:15]>[8:1](102,103)#text: ⏎',
|
|
121
|
+
'[8:1]>[8:8](103,110)html: </html>',
|
|
122
|
+
'[8:8]>[9:1](110,111)#text: ⏎',
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('mutable text node', () => {
|
|
127
|
+
const doc = parse('<title>{ title }</title>');
|
|
128
|
+
expect(nodeListToDebugMaps(doc.nodeList)).toStrictEqual([
|
|
129
|
+
'[1:1]>[1:8](0,7)title: <title>',
|
|
130
|
+
'[1:8]>[1:17](7,16)#ps:smarty-scriptlet: {␣title␣}',
|
|
131
|
+
'[1:17]>[1:25](16,24)title: </title>',
|
|
132
|
+
]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('Tags', () => {
|
|
137
|
+
it('smarty-comment', () => {
|
|
138
|
+
expect(parse('{* any *}').nodeList[0].nodeName).toBe('#ps:smarty-comment');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('smarty-scriptlet', () => {
|
|
142
|
+
expect(parse('{ any }').nodeList[0].nodeName).toBe('#ps:smarty-scriptlet');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('Issues', () => {
|
|
147
|
+
test('#470', () => {
|
|
148
|
+
const ast = parse("<script>{literal}const obj = { foo: 'bar' };{/literal}</script>");
|
|
149
|
+
expect(nodeListToDebugMaps(ast.nodeList)).toStrictEqual([
|
|
150
|
+
'[1:1]>[1:9](0,8)script: <script>',
|
|
151
|
+
"[1:9]>[1:55](8,54)#ps:smarty-literal: {literal}const␣obj␣=␣{␣foo:␣'bar'␣};{/literal}",
|
|
152
|
+
'[1:55]>[1:64](54,63)script: </script>',
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
});
|