返回 slidev
codeblock-patch.ts
根目录 / packages / vscode / syntaxes / codeblock-patch.ts
1 import Markdown from 'tm-grammars/grammars/markdown.json' with { type: 'json' }
2
3 const base = {
4 $schema: 'https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json',
5 fileTypes: [],
6 injectionSelector: 'L:text.html.markdown -markup.frontmatter.slidev -markup.fenced_code.block.markdown',
7 patterns: [
8 ],
9 repository: {
10 fenced_code_block_unknown: {
11 begin: '(^|\\G)(\\s*)(`{3,}|~{3,})\\s*(?=([^`]*)?$)',
12 beginCaptures: {
13 3: {
14 name: 'punctuation.definition.markdown',
15 },
16 4: {
17 name: 'fenced_code.block.language.attributes.markdown',
18 patterns: [],
19 },
20 },
21 end: '(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$',
22 endCaptures: {
23 3: {
24 name: 'punctuation.definition.markdown',
25 },
26 },
27 name: 'markup.fenced_code.block.markdown',
28 },
29 },
30 scopeName: 'inject-to-markdown.codeblock.patch.slidev',
31 } as any
32
33 export function generateCodeblockPatch() {
34 for (const [k, v] of Object.entries(Markdown.repository) as any) {
35 if (!k.startsWith('fenced_code_block_') || k === 'fenced_code_block_unknown')
36 continue
37 v.beginCaptures[5].patterns = []
38 base.patterns.push(v)
39 }
40
41 base.patterns.push(
42 {
43 include: '#fenced_code_block_unknown',
44 },
45 )
46 return base
47 }
48
48 lines TYPESCRIPT