PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.13.0
Code Block Pro – Beautiful Syntax Highlighting v1.13.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / util / languages.ts

languages.ts in Code Block Pro – Beautiful Syntax Highlighting 1.13.0, at src/util/languages.ts

74 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Lang as LangShiki } from 'shiki';
2 import defaultLanguages from '../defaultLanguages.json';
3 import { Lang } from '../types';
4
5 export const codeAliases = {
6 'actionscript-3': ['as3'],
7 bat: ['batch'],
8 berry: ['be'],
9 cadence: ['cdc'],
10 clojure: ['clj'],
11 codeql: ['ql'],
12 cpp: ['arduino'],
13 csharp: ['c#', 'cs'],
14 erlang: ['erl'],
15 fsharp: ['f#'],
16 haskell: ['hs'],
17 handlebars: ['hbs'],
18 'html-ruby-erb': ['erb'],
19 java: ['javafx'],
20 javascript: ['jscript', 'js'],
21 jssm: ['fsl'],
22 make: ['makefile'],
23 markdown: ['md'],
24 matlab: ['matlabkey'],
25 'objective-c': ['objc'],
26 pascal: ['delphi'],
27 powershell: ['ps', 'ps1'],
28 pug: ['jade'],
29 python: ['py'],
30 raku: ['perl6'],
31 ruby: ['rb'],
32 rust: ['rs'],
33 shaderlab: ['shader'],
34 shellscript: ['shell', 'bash', 'sh', 'zsh'],
35 stylus: ['styl'],
36 typescript: ['ts'],
37 vb: ['cmd'],
38 viml: ['vim', 'vimscript'],
39 wenyan: ['文言'],
40 xml: ['coldfusion'],
41 yaml: ['yml'],
42 };
43
44 export const getMainAlias = (
45 languageAltName: string | undefined,
46 ): string | undefined => {
47 if (!languageAltName) return;
48 return Object.keys(codeAliases).find((key) =>
49 codeAliases[key as keyof typeof codeAliases].includes(languageAltName),
50 );
51 };
52
53 export const removeAliases = (
54 langs: typeof defaultLanguages,
55 ): Partial<typeof defaultLanguages> => {
56 const aliasesToRemove = Object.values(codeAliases).flat();
57 return Object.keys(langs).reduce((acc, key) => {
58 if (!aliasesToRemove.includes(key)) {
59 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
60 // @ts-ignore
61 acc[key as Lang] = langs[key as Lang];
62 }
63 return acc;
64 }, {} as Partial<typeof defaultLanguages>);
65 };
66
67 export const languages = removeAliases(defaultLanguages);
68
69 /** Get the language shown in the editor, which could differ from the front */
70 export const getEditorLanguage = (language: string): LangShiki => {
71 if (language === 'ansi') return 'shellscript';
72 return language as LangShiki;
73 };
74