miki-template 1.2.0 → 1.3.3

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.
Files changed (60) hide show
  1. package/.github/release-notes/v1.3.1.md +55 -0
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +43 -26
  4. package/assets/banner.png +0 -0
  5. package/benchmarks/stress.mjs +647 -0
  6. package/dir/base.html +23 -0
  7. package/dir/cmpnt.html +11 -0
  8. package/dir/footer.html +3 -0
  9. package/dir/home.html +80 -0
  10. package/dir/navbar.html +9 -0
  11. package/docs/api.md +20 -3
  12. package/docs/filters.md +301 -133
  13. package/docs/partialdef.md +30 -1
  14. package/docs/tags.md +63 -0
  15. package/docs/usage.md +50 -3
  16. package/eslint.config.mjs +9 -1
  17. package/ex.mjs +33 -0
  18. package/miki-template-extension/.github/workflows/ci.yml +116 -0
  19. package/miki-template-extension/.vscodeignore +7 -0
  20. package/miki-template-extension/CHANGELOG.md +99 -0
  21. package/miki-template-extension/README.md +244 -53
  22. package/miki-template-extension/extension.js +1013 -0
  23. package/miki-template-extension/icon.png +0 -0
  24. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  25. package/miki-template-extension/package.json +244 -10
  26. package/miki-template-extension/snippets/miki-template.json +612 -72
  27. package/miki-template-extension/syntaxes/language-configuration.json +101 -13
  28. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +270 -61
  29. package/miki-template-extension/tests/grammar-tests.json +162 -0
  30. package/miki-template-extension/tests/run-grammar-tests.js +82 -0
  31. package/package.json +7 -4
  32. package/scripts/build-vsix.js +129 -0
  33. package/scripts/build-vsix.ps1 +15 -0
  34. package/src/cache.js +41 -2
  35. package/src/context.js +9 -5
  36. package/src/context_processors.js +9 -2
  37. package/src/esm.mjs +12 -0
  38. package/src/filters.js +472 -24
  39. package/src/index.js +571 -85
  40. package/src/lexer.js +76 -54
  41. package/src/libraries.js +134 -3
  42. package/src/parser.js +22 -2
  43. package/src/security.js +4 -2
  44. package/src/tags/control.js +150 -21
  45. package/src/tags/extra.js +154 -0
  46. package/src/tags/i18n.js +49 -23
  47. package/src/tags/inheritance.js +142 -23
  48. package/src/tags/util.js +102 -24
  49. package/tests/esm.test.mjs +37 -2
  50. package/tests/filters.test.js +155 -0
  51. package/tests/integration/README.md +32 -0
  52. package/tests/integration/features.test.cjs +1681 -0
  53. package/tests/integration/features.test.mjs +1697 -0
  54. package/tests/integration/templates/base.miki +6 -0
  55. package/tests/integration/templates/child.miki +6 -0
  56. package/tests/integration/templates/index.html +17 -0
  57. package/tests/parser.test.js +5 -3
  58. package/tests/partialdef.test.js +40 -1
  59. package/tests/tags.test.js +30 -0
  60. package/miki-template-1.2.0.vsix +0 -0
@@ -4,23 +4,111 @@
4
4
  "blockComment": ["{#", "#}"]
5
5
  },
6
6
  "brackets": [
7
- ["{", "}"],
7
+ ["{%", "%}"],
8
+ ["{{", "}}"],
9
+ ["{#", "#}"],
10
+ ["<", ">"],
11
+ ["(", ")"],
8
12
  ["[", "]"],
9
- ["(", ")"]
13
+ ["{", "}"]
10
14
  ],
11
15
  "autoClosingPairs": [
12
- { "open": "{", "close": "}" },
13
- { "open": "[", "close": "]" },
14
- { "open": "(", "close": ")" },
15
- { "open": "\"", "close": "\"", "notIn": ["string"] },
16
- { "open": "'", "close": "'", "notIn": ["string", "comment"] }
16
+ {
17
+ "open": "{%",
18
+ "close": "%}"
19
+ },
20
+ {
21
+ "open": "{{",
22
+ "close": "}}"
23
+ },
24
+ {
25
+ "open": "{#",
26
+ "close": "#}"
27
+ },
28
+ {
29
+ "open": "<",
30
+ "close": ">",
31
+ "notIn": ["string", "comment"]
32
+ },
33
+ {
34
+ "open": "\"",
35
+ "close": "\"",
36
+ "notIn": [
37
+ "string"
38
+ ]
39
+ },
40
+ {
41
+ "open": "'",
42
+ "close": "'",
43
+ "notIn": [
44
+ "string",
45
+ "comment"
46
+ ]
47
+ },
48
+ {
49
+ "open": "(",
50
+ "close": ")"
51
+ },
52
+ {
53
+ "open": "[",
54
+ "close": "]"
55
+ },
56
+ {
57
+ "open": "{",
58
+ "close": "}"
59
+ }
17
60
  ],
18
61
  "surroundingPairs": [
19
- { "open": "{", "close": "}" },
20
- { "open": "[", "close": "]" },
21
- { "open": "(", "close": ")" },
22
- { "open": "\"", "close": "\"" },
23
- { "open": "'", "close": "'" }
62
+ {
63
+ "open": "{%",
64
+ "close": "%}"
65
+ },
66
+ {
67
+ "open": "{{",
68
+ "close": "}}"
69
+ },
70
+ {
71
+ "open": "{#",
72
+ "close": "#}"
73
+ },
74
+ {
75
+ "open": "<",
76
+ "close": ">"
77
+ },
78
+ {
79
+ "open": "\"",
80
+ "close": "\""
81
+ },
82
+ {
83
+ "open": "'",
84
+ "close": "'"
85
+ },
86
+ {
87
+ "open": "(",
88
+ "close": ")"
89
+ },
90
+ {
91
+ "open": "[",
92
+ "close": "]"
93
+ },
94
+ {
95
+ "open": "{",
96
+ "close": "}"
97
+ }
24
98
  ],
25
- "wordPattern": "[a-zA-Z_][a-zA-Z0-9_.]*"
99
+ "folding": {
100
+ "markers": {
101
+ "start": "{%\\s*(block|for|if|with|autoescape|spaceless|verbatim|comment|partialdef|cache|filter|blocktrans|regroup|language|addtoblock|style|script)\\b",
102
+ "end": "{%\\s*end(block|for|if|with|autoescape|spaceless|verbatim|comment|partialdef|endcache|endfilter|blocktrans|endblocktrans|endlanguage|endaddtoblock)|</(style|script)>"
103
+ }
104
+ },
105
+ "wordPattern": "[a-zA-Z_][a-zA-Z0-9_.]*",
106
+ "indentationRules": {
107
+ "increaseIndentPattern": "{%\\s*(block|for|if|with|autoescape|spaceless|verbatim|comment|partialdef|cache|filter|blocktrans|regroup|language|addtoblock)\\b[^}]*%}|(<(?!(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)[^>]*>)[^>]*>)\\s*$",
108
+ "decreaseIndentPattern": "{%\\s*end(block|for|if|with|autoescape|spaceless|verbatim|comment|partialdef|endcache|endfilter|blocktrans|endblocktrans|endlanguage|endaddtoblock)\\b|</(html|head|body|div|section|article|aside|header|footer|nav|main|form|table|tr|td|th|tbody|thead|style|script)>"
109
+ },
110
+ "formatTabSize": 2,
111
+ "formatIndentSize": 2,
112
+ "formatOnSave": false,
113
+ "formatDefaultFormatter": "esbenp.prettier-vscode"
26
114
  }
@@ -1,146 +1,355 @@
1
1
  {
2
- "scopeName": "text.html.miki",
2
+ "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3
3
  "name": "miki-template",
4
+ "scopeName": "text.html.miki",
5
+ "fileTypes": ["miki", "miki-template", "html", "django", "dj"],
6
+ "tokenColors": [
7
+ {
8
+ "name": "Template Tags",
9
+ "scope": ["entity.name.tag.django"],
10
+ "settings": {
11
+ "foreground": "#E8BF6A",
12
+ "fontStyle": "bold"
13
+ }
14
+ },
15
+ {
16
+ "name": "Template Variables (block.super)",
17
+ "scope": ["variable.other.django"],
18
+ "settings": {
19
+ "foreground": "#9CDCFE"
20
+ }
21
+ },
22
+ {
23
+ "name": "Template Filter Functions",
24
+ "scope": ["support.function.django"],
25
+ "settings": {
26
+ "foreground": "#4EC9B0"
27
+ }
28
+ },
29
+ {
30
+ "name": "Template Strings",
31
+ "scope": ["string.quoted.double.django", "string.quoted.single.django"],
32
+ "settings": {
33
+ "foreground": "#CE9178"
34
+ }
35
+ },
36
+ {
37
+ "name": "Template Numbers",
38
+ "scope": ["constant.numeric.django"],
39
+ "settings": {
40
+ "foreground": "#B5CEA8"
41
+ }
42
+ },
43
+ {
44
+ "name": "Template Language Constants",
45
+ "scope": ["constant.language.django"],
46
+ "settings": {
47
+ "foreground": "#569CD6"
48
+ }
49
+ },
50
+ {
51
+ "name": "Template Operators",
52
+ "scope": ["keyword.operator.django"],
53
+ "settings": {
54
+ "foreground": "#D4D4D4",
55
+ "fontStyle": "bold"
56
+ }
57
+ },
58
+ {
59
+ "name": "Template Punctuation",
60
+ "scope": ["punctuation.separator.django", "punctuation.separator.key-value.django"],
61
+ "settings": {
62
+ "foreground": "#808080"
63
+ }
64
+ },
65
+ {
66
+ "name": "Template Comments",
67
+ "scope": ["comment.block.django"],
68
+ "settings": {
69
+ "foreground": "#6A9955",
70
+ "fontStyle": "italic"
71
+ }
72
+ },
73
+ {
74
+ "name": "Template Filter Punctuation",
75
+ "scope": ["punctuation.separator.filter.django", "punctuation.separator.filter-argument.django"],
76
+ "settings": {
77
+ "foreground": "#C586C0"
78
+ }
79
+ },
80
+ {
81
+ "name": "Prettier Ignore",
82
+ "scope": ["meta.prettier-ignore.django", "meta.prettier-ignore-region.django"],
83
+ "settings": {
84
+ "foreground": "#FFDD00",
85
+ "fontStyle": "italic"
86
+ }
87
+ }
88
+ ],
4
89
  "patterns": [
5
90
  {
6
- "include": "#comment"
91
+ "include": "#comments"
92
+ },
93
+ {
94
+ "include": "#prettier-ignore"
95
+ },
96
+ {
97
+ "include": "#prettier-ignore-region"
7
98
  },
8
99
  {
9
- "include": "#tag"
100
+ "include": "#tag-block"
10
101
  },
11
102
  {
12
- "include": "#variable"
103
+ "include": "#variable-block"
13
104
  },
14
105
  {
15
- "include": "#string"
106
+ "include": "#embedded-html"
16
107
  }
17
108
  ],
18
109
  "repository": {
19
- "comment": {
20
- "name": "comment.block.miki",
21
- "begin": "\\{#",
22
- "end": "#\\}",
110
+ "comments": {
111
+ "patterns": [
112
+ {
113
+ "name": "comment.block.django",
114
+ "begin": "\\{#",
115
+ "end": "#\\}",
116
+ "beginCaptures": {
117
+ "0": { "name": "punctuation.definition.comment.begin.django" }
118
+ },
119
+ "endCaptures": {
120
+ "0": { "name": "punctuation.definition.comment.end.django" }
121
+ }
122
+ }
123
+ ]
124
+ },
125
+ "prettier-ignore": {
126
+ "name": "meta.prettier-ignore.django",
127
+ "match": "\\{#\\s*prettier-ignore\\s*#\\}",
128
+ "captures": {
129
+ "0": { "name": "comment.block.django" }
130
+ }
131
+ },
132
+ "prettier-ignore-region": {
133
+ "name": "meta.prettier-ignore-region.django",
134
+ "begin": "\\{#\\s*prettier-ignore-start\\s*#\\}",
135
+ "end": "\\{#\\s*prettier-ignore-end\\s*#\\}",
23
136
  "beginCaptures": {
24
- "0": { "name": "punctuation.definition.comment.begin.miki" }
137
+ "0": { "name": "punctuation.definition.comment.begin.django" }
25
138
  },
26
139
  "endCaptures": {
27
- "0": { "name": "punctuation.definition.comment.end.miki" }
140
+ "0": { "name": "punctuation.definition.comment.end.django" }
28
141
  }
29
142
  },
30
- "tag": {
31
- "name": "meta.tag.miki",
32
- "begin": "\\{%",
33
- "end": "%\\}",
143
+ "tag-block": {
144
+ "name": "meta.tag.django",
145
+ "begin": "(\\{%)(-?|\\s*)",
146
+ "end": "(-?\\s*%\\})",
34
147
  "beginCaptures": {
35
- "0": { "name": "punctuation.definition.tag.begin.miki" }
148
+ "1": { "name": "punctuation.definition.tag.begin.django" }
36
149
  },
37
150
  "endCaptures": {
38
- "0": { "name": "punctuation.definition.tag.end.miki" }
151
+ "1": { "name": "punctuation.definition.tag.end.django" }
39
152
  },
40
153
  "patterns": [
41
154
  {
42
- "name": "entity.name.tag.miki",
43
- "match": "(?i)\\b(if|elif|else|endif|for|empty|endfor|with|endwith|cycle|comment|endcomment|verbatim|endverbatim|include|extends|block|endblock|partialdef|endpartialdef|partial|load|templatetag|trans|blocktrans|language|endlanguage|plural|widthratio|debug|endif|endfor|endwith|endblock|endcomment|endverbatim|endpartialdef|endblocktrans|endlanguage|endcache|endmarkdown)\\b"
155
+ "name": "entity.name.tag.django",
156
+ "match": "(?i)\\b(if|elif|else|endif|for|empty|endfor|with|endwith|cycle|firstof|comment|endcomment|verbatim|endverbatim|include|extends|block|endblock|block.super|partialdef|endpartialdef|partial|load|splural|autoescape|autoescapeoff|endautoescape|filter|endfilter|spaceless|endspaceless|templatetag|endtemplatetag|trans|blocktrans|endblocktrans|language|endlanguage|plural|regroup|widthratio|debug|csrf_token|csp_nonce_attr|static|url|addtoblock|endaddtoblock)\\b"
157
+ },
158
+ {
159
+ "name": "variable.other.django",
160
+ "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
44
161
  },
45
162
  {
46
- "name": "string.quoted.double.miki",
163
+ "name": "string.quoted.double.django",
47
164
  "match": "\"[^\"]*\""
48
165
  },
49
166
  {
50
- "name": "string.quoted.single.miki",
167
+ "name": "string.quoted.single.django",
51
168
  "match": "'[^']*'"
52
169
  },
53
170
  {
54
- "name": "constant.numeric.miki",
55
- "match": "\\b\\d+\\b"
171
+ "name": "constant.numeric.django",
172
+ "match": "\\b\\d+\\.?\\d*\\b"
56
173
  },
57
174
  {
58
- "name": "keyword.operator.miki",
175
+ "name": "constant.language.django",
176
+ "match": "\\b(true|false|null|undefined)\\b"
177
+ },
178
+ {
179
+ "name": "keyword.operator.django",
59
180
  "match": "(?i)\\b(and|or|not|in|not in)\\b"
60
181
  },
61
182
  {
62
- "name": "punctuation.separator.miki",
183
+ "name": "punctuation.separator.django",
63
184
  "match": "="
185
+ },
186
+ {
187
+ "name": "punctuation.separator.key-value.django",
188
+ "match": "\\b(as)\\b"
64
189
  }
65
190
  ]
66
191
  },
67
- "variable": {
68
- "name": "variable.other.miki",
69
- "begin": "\\{\\{",
70
- "end": "\\}\\}",
192
+ "variable-block": {
193
+ "name": "meta.variable.django",
194
+ "begin": "(\\{\\{)(-?|\\s*)",
195
+ "end": "(-?\\s*\\}\\})",
71
196
  "beginCaptures": {
72
- "0": { "name": "punctuation.definition.variable.begin.miki" }
197
+ "1": { "name": "punctuation.definition.variable.begin.django" }
73
198
  },
74
199
  "endCaptures": {
75
- "0": { "name": "punctuation.definition.variable.end.miki" }
200
+ "1": { "name": "punctuation.definition.variable.end.django" }
76
201
  },
77
202
  "patterns": [
78
203
  {
79
- "name": "variable.other.miki",
80
- "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
204
+ "include": "#django-variables"
81
205
  },
82
206
  {
83
- "include": "#filter"
207
+ "include": "#filters"
208
+ }
209
+ ]
210
+ },
211
+ "django-variables": {
212
+ "patterns": [
213
+ {
214
+ "name": "variable.other.django",
215
+ "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
84
216
  },
85
217
  {
86
- "name": "string.quoted.double.miki",
218
+ "name": "string.quoted.double.django",
87
219
  "match": "\"[^\"]*\""
88
220
  },
89
221
  {
90
- "name": "string.quoted.single.miki",
222
+ "name": "string.quoted.single.django",
91
223
  "match": "'[^']*'"
224
+ },
225
+ {
226
+ "name": "constant.numeric.django",
227
+ "match": "\\b\\d+\\.?\\d*\\b"
92
228
  }
93
229
  ]
94
230
  },
95
- "filter": {
96
- "name": "meta.filter.miki",
97
- "begin": "\\|",
98
- "end": "(?=\\}|$)",
231
+ "filters": {
232
+ "name": "meta.filter.django",
233
+ "begin": "(\\|)",
234
+ "end": "(\\}\\}|\\|$)",
99
235
  "beginCaptures": {
100
- "0": { "name": "punctuation.separator.filter.miki" }
236
+ "1": { "name": "punctuation.separator.filter.django" }
237
+ },
238
+ "endCaptures": {
239
+ "1": { "name": "punctuation.separator.filter.django" }
101
240
  },
102
241
  "patterns": [
103
242
  {
104
- "name": "support.function.miki",
105
- "match": "[a-zA-Z_][a-zA-Z0-9_]*"
243
+ "name": "support.function.django",
244
+ "match": "(?i)\\b(upper|lower|title|capfirst|slugify|wordcount|striptags|truncatewords|truncatechars|truncatewords_html|truncatechars_html|linebreaks|linebreaksbr|cut|addslashes|removetags|safe|escape|escapejs|urlencode|escapeuri|urlize|stringformat|center|ljust|rjust|length|length_is|join|slice|first|last|dictsort|dictsortreversed|default|default_if_none|firstof|date|time|strftime|date_format|timesince|timeuntil|add|addtoblock|divisibleby|floatformat|yesno|pluralize|pluralize_either|filesizeformat|trans|regroup|intcomma|intword|apnumber|ordinal|naturalday|ordinal|lorem|get_digit|phone2numeric|pprint|make_list|unordered_list|json_script|json_script_filter|urt|datetime|field_class|strip|force_escape|linebreak_filter|truncatewords_filter|truncatechars_filter|safeseq|unordered_list|random|filesizeformat_pprint)\\b"
106
245
  },
107
246
  {
108
- "begin": ":",
247
+ "name": "punctuation.separator.filter-argument.django",
248
+ "begin": "(:)",
249
+ "end": "(?=\\||\\}\\})",
109
250
  "beginCaptures": {
110
- "0": { "name": "punctuation.separator.filter.argument.miki" }
251
+ "1": { "name": "punctuation.separator.filter.argument.django" }
111
252
  },
112
- "end": "(?=\\||\\}\\})",
113
253
  "patterns": [
114
254
  {
115
- "name": "string.quoted.double.miki",
255
+ "name": "string.quoted.double.django",
116
256
  "match": "\"[^\"]*\""
117
257
  },
118
258
  {
119
- "name": "string.quoted.single.miki",
259
+ "name": "string.quoted.single.django",
120
260
  "match": "'[^']*'"
121
261
  },
122
262
  {
123
- "name": "constant.numeric.miki",
124
- "match": "\\b\\d+\\b"
263
+ "name": "constant.numeric.django",
264
+ "match": "\\b\\d+\\.?\\d*\\b"
125
265
  },
126
266
  {
127
- "name": "variable.other.miki",
267
+ "name": "variable.other.django",
128
268
  "match": "[a-zA-Z_][a-zA-Z0-9_.]*"
129
269
  }
130
270
  ]
131
271
  }
132
272
  ]
133
273
  },
134
- "string": {
135
- "name": "string.quoted.double.miki",
136
- "begin": "\"",
137
- "end": "\"",
138
- "beginCaptures": {
139
- "0": { "name": "punctuation.definition.string.begin.miki" }
140
- },
141
- "endCaptures": {
142
- "0": { "name": "punctuation.definition.string.end.miki" }
143
- }
274
+ "embedded-html": {
275
+ "patterns": [
276
+ {
277
+ "name": "meta.tag.any.html",
278
+ "begin": "(<)(style)\\b(?=[^>]*>)",
279
+ "end": "(</)(style)(>)",
280
+ "beginCaptures": {
281
+ "1": { "name": "punctuation.definition.tag.begin.html" },
282
+ "2": { "name": "entity.name.tag.style.html" }
283
+ },
284
+ "endCaptures": {
285
+ "1": { "name": "punctuation.definition.tag.begin.html" },
286
+ "2": { "name": "entity.name.tag.style.html" },
287
+ "3": { "name": "punctuation.definition.tag.end.html" }
288
+ },
289
+ "patterns": [
290
+ {
291
+ "include": "source.css"
292
+ }
293
+ ]
294
+ },
295
+ {
296
+ "name": "meta.tag.any.html",
297
+ "begin": "(<)(script)\\b(?=[^>]*>)",
298
+ "end": "(</)(script)(>)",
299
+ "beginCaptures": {
300
+ "1": { "name": "punctuation.definition.tag.begin.html" },
301
+ "2": { "name": "entity.name.tag.script.html" }
302
+ },
303
+ "endCaptures": {
304
+ "1": { "name": "punctuation.definition.tag.begin.html" },
305
+ "2": { "name": "entity.name.tag.script.html" },
306
+ "3": { "name": "punctuation.definition.tag.end.html" }
307
+ },
308
+ "patterns": [
309
+ {
310
+ "include": "source.js"
311
+ }
312
+ ]
313
+ },
314
+ {
315
+ "name": "text.html.basic",
316
+ "begin": "(<)(?![\\?%])",
317
+ "end": "(>)",
318
+ "beginCaptures": {
319
+ "1": { "name": "punctuation.definition.tag.begin.html" }
320
+ },
321
+ "endCaptures": {
322
+ "1": { "name": "punctuation.definition.tag.end.html" }
323
+ },
324
+ "patterns": [
325
+ {
326
+ "name": "entity.name.tag.html",
327
+ "match": "\\/?([a-zA-Z][a-zA-Z0-9:-]*)\\/?"
328
+ },
329
+ {
330
+ "name": "meta.attribute.html",
331
+ "begin": "\\b([a-zA-Z:-]+)(?=\\s*=)",
332
+ "beginCaptures": {
333
+ "1": { "name": "entity.other.attribute-name.html" }
334
+ },
335
+ "patterns": [
336
+ {
337
+ "name": "string.quoted.double.html",
338
+ "match": "\"([^\"]*)\""
339
+ },
340
+ {
341
+ "name": "string.quoted.single.html",
342
+ "match": "'([^']*)'"
343
+ },
344
+ {
345
+ "name": "string.unquoted.html",
346
+ "match": "[^\\s>]+"
347
+ }
348
+ ]
349
+ }
350
+ ]
351
+ }
352
+ ]
144
353
  }
145
354
  }
146
355
  }