@peaceroad/markdown-it-renderer-fence 0.7.0 → 0.8.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.
@@ -4,12 +4,85 @@ const shikiFunctionLikeIdentifierReg = /^[A-Za-z_$][\w$]*[!?]?$/
4
4
  const shikiShellOptionTokenReg = /^-[A-Za-z0-9][A-Za-z0-9-]*$/
5
5
  const shikiShellTestOperatorSet = new Set(['-n', '-z', '-gt', '-lt', '-ge', '-le', '-eq', '-ne'])
6
6
 
7
- const keywordV4GlobalRules = [
7
+ const roleV4GlobalRules = [
8
8
  {
9
- id: 'css-color-name-to-number',
9
+ id: 'string-delimiter-punctuation',
10
+ priority: 2300,
11
+ scopeIncludesAny: ['punctuation.definition.string'],
12
+ tokenRegex: /^(?:\$?['"`]+|[<>])$/,
13
+ setBucket: 'punctuation',
14
+ },
15
+ {
16
+ id: 'string-interpolation-punctuation',
17
+ priority: 2295,
18
+ baseIn: ['string', 'string-unquoted'],
19
+ scopeIncludesAny: [
20
+ 'punctuation.definition.interpolation',
21
+ 'punctuation.section.embedded',
22
+ 'punctuation.accessor',
23
+ ],
24
+ tokenKind: 'punctuation',
25
+ setBucket: 'punctuation',
26
+ },
27
+ {
28
+ id: 'variable-prefix-punctuation',
29
+ priority: 2292,
30
+ scopeIncludesAny: ['punctuation.definition.variable'],
31
+ tokenKind: 'punctuation',
32
+ setBucket: 'punctuation',
33
+ },
34
+ {
35
+ id: 'generic-definition-punctuation',
36
+ priority: 2291,
37
+ scopeIncludesAny: ['punctuation.definition.'],
38
+ tokenKind: 'punctuation',
39
+ setBucket: 'punctuation',
40
+ },
41
+ {
42
+ id: 'generic-section-punctuation',
43
+ priority: 2290,
44
+ scopeIncludesAny: ['punctuation.section.'],
45
+ tokenKind: 'punctuation',
46
+ setBucket: 'punctuation',
47
+ },
48
+ {
49
+ id: 'object-literal-key-variable',
50
+ priority: 2289,
51
+ scopeIncludesAny: ['meta.object-literal.key'],
52
+ tokenKind: 'identifier',
53
+ setBucket: 'variable',
54
+ },
55
+ {
56
+ id: 'symbolic-operator-punctuation',
57
+ priority: 2280,
58
+ scopeIncludesAny: [
59
+ 'keyword.operator.accessor',
60
+ 'keyword.operator.arithmetic',
61
+ 'keyword.operator.assignment',
62
+ 'keyword.operator.bitwise',
63
+ 'keyword.operator.comparison',
64
+ 'keyword.operator.expression',
65
+ 'keyword.operator.logical',
66
+ 'keyword.operator.nullish',
67
+ 'keyword.operator.optional',
68
+ 'keyword.operator.spread',
69
+ 'keyword.operator.ternary',
70
+ ],
71
+ tokenKind: 'punctuation',
72
+ setBucket: 'punctuation',
73
+ },
74
+ {
75
+ id: 'json-property-name-delimiter-punctuation',
76
+ priority: 2270,
77
+ scopeIncludesAny: ['punctuation.support.type.property-name'],
78
+ tokenKind: 'punctuation',
79
+ setBucket: 'punctuation',
80
+ },
81
+ {
82
+ id: 'css-color-name-to-literal',
10
83
  priority: 2100,
11
84
  scopeIncludesAny: ['support.constant.color.w3c-standard-color-name.css'],
12
- setBucket: 'number',
85
+ setBucket: 'literal',
13
86
  },
14
87
  {
15
88
  id: 'rust-lifetime-to-type-name',
@@ -19,30 +92,45 @@ const keywordV4GlobalRules = [
19
92
  setBucket: 'type-name',
20
93
  },
21
94
  {
22
- id: 'regex-alternative-operator-keyword',
95
+ id: 'regex-alternative-operator-punctuation',
23
96
  priority: 2040,
24
97
  scopeIncludesAny: ['keyword.operator.or.regexp'],
25
98
  tokenEquals: ['|'],
26
- setBucket: 'keyword',
99
+ setBucket: 'punctuation',
27
100
  },
28
101
  ]
29
102
 
30
- const keywordV4LangRules = {
103
+ const roleV4LangRules = {
31
104
  sql: [
32
105
  {
33
- id: 'sql-window-function-blue',
106
+ id: 'sql-plain-source-punctuation-text',
107
+ priority: 2010,
108
+ scopeIncludesAny: ['source.sql'],
109
+ scopeExcludesAny: ['keyword.operator', 'punctuation.definition.string'],
110
+ tokenKind: 'punctuation',
111
+ setBucket: 'text',
112
+ },
113
+ {
114
+ id: 'sql-window-function-title',
34
115
  priority: 2000,
35
116
  scopeIncludesAny: ['support.function.ranking.sql'],
36
- setBucket: 'type',
117
+ setBucket: 'title-function',
37
118
  },
38
119
  {
39
- id: 'sql-table-database-name-blue',
120
+ id: 'sql-table-database-name-text',
40
121
  priority: 1980,
41
122
  scopeIncludesAny: ['constant.other.table-name.sql', 'constant.other.database-name.sql'],
42
- setBucket: 'type',
123
+ setBucket: 'text',
43
124
  },
44
125
  ],
45
126
  java: [
127
+ {
128
+ id: 'java-storage-modifier-keyword',
129
+ priority: 2000,
130
+ scopeIncludesAny: ['storage.modifier.java', 'storage.modifier.import.java'],
131
+ tokenKind: 'identifier',
132
+ setBucket: 'keyword',
133
+ },
46
134
  {
47
135
  id: 'java-record-signature-neutral',
48
136
  priority: 1995,
@@ -51,16 +139,16 @@ const keywordV4LangRules = {
51
139
  setBucket: 'text',
52
140
  },
53
141
  {
54
- id: 'java-package-separator-neutral',
142
+ id: 'java-package-separator-punctuation',
55
143
  priority: 1980,
56
144
  scopeIncludesAny: ['punctuation.separator.java'],
57
- setBucket: 'text',
145
+ setBucket: 'punctuation',
58
146
  },
59
147
  {
60
- id: 'java-generic-bracket-neutral',
148
+ id: 'java-generic-bracket-punctuation',
61
149
  priority: 1970,
62
150
  scopeIncludesAny: ['punctuation.bracket.angle.java'],
63
- setBucket: 'text',
151
+ setBucket: 'punctuation',
64
152
  },
65
153
  {
66
154
  id: 'java-record-keyword',
@@ -93,16 +181,22 @@ const keywordV4LangRules = {
93
181
  setBucket: 'title-function-builtin',
94
182
  },
95
183
  {
96
- id: 'php-core-const-blue',
184
+ id: 'php-file-and-declare-meta-text',
185
+ priority: 1990,
186
+ scopeIncludesAny: ['constant.other.php'],
187
+ setBucket: 'text',
188
+ },
189
+ {
190
+ id: 'php-core-const-literal',
97
191
  priority: 1980,
98
- scopeIncludesAny: ['support.constant.core.php', 'constant.other.php'],
99
- setBucket: 'variable-const',
192
+ scopeIncludesAny: ['support.constant.core.php'],
193
+ setBucket: 'literal',
100
194
  },
101
195
  {
102
- id: 'php-enum-const-blue',
196
+ id: 'php-enum-const-text',
103
197
  priority: 1970,
104
198
  scopeIncludesAny: ['constant.enum.php', 'constant.other.class.php'],
105
- setBucket: 'variable-const',
199
+ setBucket: 'text',
106
200
  },
107
201
  ],
108
202
  ruby: [
@@ -112,6 +206,20 @@ const keywordV4LangRules = {
112
206
  scopeIncludesAny: ['entity.name.function.ruby'],
113
207
  setBucket: 'title-function',
114
208
  },
209
+ {
210
+ id: 'ruby-instance-variable-token',
211
+ priority: 1990,
212
+ scopeIncludesAny: ['variable.other.readwrite.instance.ruby', 'variable.other.block.ruby'],
213
+ tokenKind: 'identifier',
214
+ setBucket: 'variable',
215
+ },
216
+ {
217
+ id: 'ruby-variable-separator-punctuation',
218
+ priority: 1985,
219
+ scopeIncludesAny: ['punctuation.separator.variable.ruby'],
220
+ tokenKind: 'punctuation',
221
+ setBucket: 'punctuation',
222
+ },
115
223
  {
116
224
  id: 'ruby-variable-accent',
117
225
  priority: 1980,
@@ -152,12 +260,35 @@ const keywordV4LangRules = {
152
260
  },
153
261
  ],
154
262
  csharp: [
263
+ {
264
+ id: 'csharp-new-expression-punctuation',
265
+ priority: 1970,
266
+ scopeIncludesAny: ['keyword.operator.expression.new.cs', 'punctuation.parenthesis.open.cs'],
267
+ tokenRegex: /^new\(?$/,
268
+ setBucket: 'punctuation',
269
+ },
155
270
  {
156
271
  id: 'csharp-keyword-type-keyword',
157
272
  priority: 1960,
158
273
  scopeIncludesAny: ['keyword.type.string.cs'],
159
274
  setBucket: 'keyword',
160
275
  },
276
+ {
277
+ id: 'csharp-record-parameter-name-text',
278
+ priority: 1955,
279
+ scopeIncludesAny: ['entity.name.variable.parameter.cs'],
280
+ tokenKind: 'identifier',
281
+ setBucket: 'text',
282
+ },
283
+ {
284
+ id: 'csharp-plain-source-identifier-text',
285
+ priority: 1950,
286
+ baseIn: ['type-name', 'type', 'variable-plain'],
287
+ scopeIncludesAny: ['source.cs'],
288
+ scopeExcludesAny: ['entity.name.', 'support.', 'storage.', 'keyword.', 'variable.'],
289
+ tokenKind: 'identifier',
290
+ setBucket: 'text',
291
+ },
161
292
  ],
162
293
  c: [
163
294
  {
@@ -177,10 +308,42 @@ const keywordV4LangRules = {
177
308
  id: 'c-placeholder-blue',
178
309
  priority: 1950,
179
310
  scopeIncludesAny: ['constant.other.placeholder.c'],
180
- setBucket: 'literal',
311
+ setBucket: 'string',
312
+ },
313
+ {
314
+ id: 'c-plain-source-identifier-text',
315
+ priority: 1940,
316
+ baseIn: ['variable-plain'],
317
+ scopeIncludesAny: ['source.c'],
318
+ scopeExcludesAny: ['variable.', 'entity.name.', 'support.', 'storage.', 'keyword.', 'constant.'],
319
+ tokenKind: 'identifier',
320
+ setBucket: 'text',
181
321
  },
182
322
  ],
183
323
  cpp: [
324
+ {
325
+ id: 'cpp-plain-function-body-fragment-text',
326
+ priority: 1985,
327
+ scopeIncludesAny: ['meta.body.function.definition.cpp'],
328
+ scopeExcludesAny: ['entity.name.', 'support.', 'storage.', 'keyword.', 'variable.', 'constant.', 'string.'],
329
+ tokenRegex: /[A-Za-z_]/,
330
+ setBucket: 'text',
331
+ },
332
+ {
333
+ id: 'cpp-plain-function-body-identifier-text',
334
+ priority: 1980,
335
+ scopeIncludesAny: ['meta.body.function.definition.cpp'],
336
+ scopeExcludesAny: ['entity.name.', 'support.', 'storage.', 'keyword.', 'variable.', 'constant.', 'string.'],
337
+ tokenKind: 'identifier',
338
+ setBucket: 'text',
339
+ },
340
+ {
341
+ id: 'cpp-scope-resolution-name-text',
342
+ priority: 1970,
343
+ scopeIncludesAny: ['entity.name.scope-resolution.cpp', 'entity.name.scope-resolution.parameter.cpp'],
344
+ tokenKind: 'identifier',
345
+ setBucket: 'text',
346
+ },
184
347
  {
185
348
  id: 'cpp-reference-modifier-keyword',
186
349
  priority: 1960,
@@ -189,6 +352,20 @@ const keywordV4LangRules = {
189
352
  },
190
353
  ],
191
354
  python: [
355
+ {
356
+ id: 'python-fstring-period-punctuation',
357
+ priority: 1920,
358
+ scopeIncludesAny: ['meta.fstring.python', 'punctuation.separator.period.python'],
359
+ tokenEquals: ['.'],
360
+ setBucket: 'punctuation',
361
+ },
362
+ {
363
+ id: 'python-meta-attribute',
364
+ priority: 1910,
365
+ scopeIncludesAny: ['meta.attribute.python'],
366
+ tokenKind: 'identifier',
367
+ setBucket: 'attribute',
368
+ },
192
369
  {
193
370
  id: 'python-fstring-conversion-neutral',
194
371
  priority: 1900,
@@ -208,23 +385,29 @@ const keywordV4LangRules = {
208
385
  ],
209
386
  css: [
210
387
  {
211
- id: 'css-function-type-blue',
388
+ id: 'css-function-title',
212
389
  priority: 1940,
213
390
  scopeIncludesAny: ['support.function.calc.css', 'support.function.gradient.css'],
214
- setBucket: 'type',
391
+ setBucket: 'title-function',
392
+ },
393
+ {
394
+ id: 'css-property-value-literal',
395
+ priority: 1930,
396
+ scopeIncludesAny: ['support.constant.property-value.css'],
397
+ setBucket: 'literal',
215
398
  },
216
399
  ],
217
400
  }
218
401
 
219
- const keywordV4SortedGlobalRules = keywordV4GlobalRules.slice().sort((a, b) => (b.priority || 0) - (a.priority || 0))
220
- const keywordV4SortedLangRules = new Map(
221
- Object.keys(keywordV4LangRules).map((lang) => [
402
+ const roleV4SortedGlobalRules = roleV4GlobalRules.slice().sort((a, b) => (b.priority || 0) - (a.priority || 0))
403
+ const roleV4SortedLangRules = new Map(
404
+ Object.keys(roleV4LangRules).map((lang) => [
222
405
  lang,
223
- keywordV4LangRules[lang].slice().sort((a, b) => (b.priority || 0) - (a.priority || 0)),
406
+ roleV4LangRules[lang].slice().sort((a, b) => (b.priority || 0) - (a.priority || 0)),
224
407
  ]),
225
408
  )
226
409
 
227
- const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
410
+ const applyShikiRoleLegacyPostRules = (currentBucket, ctx, helper) => {
228
411
  const postHelper = helper && typeof helper === 'object' ? helper : {}
229
412
  const hasAnyScopePattern = typeof postHelper.hasAnyScopePattern === 'function'
230
413
  ? postHelper.hasAnyScopePattern
@@ -245,7 +428,7 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
245
428
  if (!trimmed) return 'text'
246
429
 
247
430
  if ((langKey === 'bash' || langKey === 'shellscript') && shikiShellOptionTokenReg.test(trimmed)) {
248
- return shikiShellTestOperatorSet.has(tokenLower) ? 'keyword' : 'literal'
431
+ return shikiShellTestOperatorSet.has(tokenLower) ? 'punctuation' : 'string'
249
432
  }
250
433
  if ((langKey === 'hcl' || langKey === 'terraform') && trimmed === '=') return 'keyword'
251
434
  if (bucket === 'comment' && trimmed.startsWith('#!')) return 'meta-shebang'
@@ -262,15 +445,16 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
262
445
  trimmed.startsWith('${') ||
263
446
  trimmed === '}'
264
447
  )
265
- ) return 'literal'
448
+ ) return hasAnyScopePattern(['variable.parameter.positional.shell', 'variable.language.special.shell'])
449
+ ? 'variable-plain'
450
+ : 'string'
266
451
  if (
267
452
  (langKey === 'bash' || langKey === 'shellscript') &&
268
453
  hasAnyScopePattern(['constant.other.option'])
269
- ) return shikiShellTestOperatorSet.has(tokenLower) ? 'keyword' : 'literal'
454
+ ) return shikiShellTestOperatorSet.has(tokenLower) ? 'punctuation' : 'string'
270
455
  if (langKey === 'python' && hasAnyScopePattern(['storage.type.string.python'])) return 'keyword'
271
- if (langKey === 'go' && hasAnyScopePattern(['entity.name.import.go'])) return 'type-name'
272
456
  if (hasAnyScopePattern(['keyword.operator.string'])) return 'keyword'
273
- if (hasAnyScopePattern(['constant.character.escape', 'constant.character.format.placeholder'])) return 'number'
457
+ if (hasAnyScopePattern(['constant.character.escape', 'constant.character.format.placeholder'])) return 'literal'
274
458
  if (hasAnyScopePattern(['variable.other.', 'variable.ruby', 'meta.attribute.python'])) return 'variable-plain'
275
459
  }
276
460
  if (bucket === 'string-unquoted') {
@@ -286,16 +470,17 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
286
470
  trimmed.startsWith('${') ||
287
471
  trimmed === '}'
288
472
  )
289
- ) return 'literal'
473
+ ) return hasAnyScopePattern(['variable.parameter.positional.shell', 'variable.language.special.shell'])
474
+ ? 'variable-plain'
475
+ : 'string'
290
476
  if (
291
477
  (langKey === 'bash' || langKey === 'shellscript') &&
292
478
  hasAnyScopePattern(['constant.other.option'])
293
- ) return shikiShellTestOperatorSet.has(tokenLower) ? 'keyword' : 'literal'
479
+ ) return shikiShellTestOperatorSet.has(tokenLower) ? 'punctuation' : 'string'
294
480
  if (hasAnyScopePattern(['entity.name.tag.yaml'])) return 'tag'
295
481
  return 'string'
296
482
  }
297
483
  if (bucket === 'title-function') {
298
- if (langKey === 'css' && hasAnyScopePattern(['support.function.misc.css'])) return 'type'
299
484
  if (hasAnyScopePattern(['support.function.builtin', 'support.function.kernel', 'support.function.construct'])) return 'title-function-builtin'
300
485
  if (hasAnyScopePattern(['storage.type.function.arrow', 'keyword.operator'])) return 'keyword'
301
486
  if (hasAnyScopePattern(['punctuation.section.function', 'punctuation.definition.arguments', 'meta.function-call.arguments'])) return 'punctuation'
@@ -330,7 +515,7 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
330
515
  }
331
516
  if (bucket === 'variable-plain') {
332
517
  if (hasAnyScopePattern(['variable.other.constant', 'constant.other.php', 'variable.other.enummember'])) return 'variable-const'
333
- if (hasAnyScopePattern(['entity.name.variable.local.cs'])) return 'type-name'
518
+ if (langKey === 'csharp' && hasAnyScopePattern(['entity.name.variable.local.cs'])) return 'text'
334
519
  if (hasAnyScopePattern(['source.sql', 'source.python', 'source.ruby'])) return 'text'
335
520
  if (!shikiSimpleIdentifierReg.test(trimmed) && hasAnyScopePattern(['punctuation.'])) return 'punctuation'
336
521
  }
@@ -356,6 +541,7 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
356
541
  if (bucket === 'text') {
357
542
  const tokenBucket = classifyToken(tokenContent, langKey)
358
543
  if (tokenBucket) return tokenBucket
544
+ if (hasAnyScopePattern(['source.sql', 'source.python', 'source.ruby', 'text.html.basic'])) return 'text'
359
545
  if (shikiSimpleIdentifierReg.test(trimmed)) return 'variable-plain'
360
546
  }
361
547
  if (!shikiSimpleIdentifierReg.test(trimmed) && (bucket === 'text' || bucket === 'meta')) {
@@ -365,7 +551,7 @@ const applyShikiKeywordLegacyPostRules = (currentBucket, ctx, helper) => {
365
551
  return bucket
366
552
  }
367
553
 
368
- const matchKeywordV4Rule = (rule, currentBucket, ctx) => {
554
+ const matchRoleV4Rule = (rule, currentBucket, ctx) => {
369
555
  const hasAnyScopePattern = (ctx && typeof ctx.hasAnyScopePattern === 'function')
370
556
  ? ctx.hasAnyScopePattern
371
557
  : (() => false)
@@ -386,22 +572,21 @@ const applyRuleSet = (currentBucket, rules, ctx) => {
386
572
  let next = currentBucket
387
573
  for (let i = 0; i < rules.length; i++) {
388
574
  const rule = rules[i]
389
- if (!matchKeywordV4Rule(rule, next, ctx)) continue
575
+ if (!matchRoleV4Rule(rule, next, ctx)) continue
390
576
  next = rule.setBucket || next
391
577
  if (rule.stop !== false) break
392
578
  }
393
579
  return next
394
580
  }
395
581
 
396
- const applyKeywordV4Rules = (currentBucket, ctx) => {
397
- let next = applyRuleSet(currentBucket, keywordV4SortedGlobalRules, ctx)
398
- const langRules = keywordV4SortedLangRules.get(ctx.langKey)
582
+ const applyRoleV4Rules = (currentBucket, ctx) => {
583
+ let next = applyRuleSet(currentBucket, roleV4SortedGlobalRules, ctx)
584
+ const langRules = roleV4SortedLangRules.get(ctx.langKey)
399
585
  next = applyRuleSet(next, langRules, ctx)
400
586
  return next
401
587
  }
402
588
 
403
589
  export {
404
- applyKeywordV4Rules,
405
- applyShikiKeywordLegacyPostRules,
590
+ applyRoleV4Rules,
591
+ applyShikiRoleLegacyPostRules,
406
592
  }
407
-