]> BookStack Code Mirror - bookstack/blob - resources/js/code/modes.js
5a89255a5a803f8c8a564cf62dfd036d24e67421
[bookstack] / resources / js / code / modes.js
1 import {StreamLanguage} from "@codemirror/language"
2
3 import {css as langCss} from '@codemirror/legacy-modes/mode/css';
4 import {clike as langClike} from '@codemirror/legacy-modes/mode/clike';
5 import {diff as langDiff} from '@codemirror/legacy-modes/mode/diff';
6 import {fortran as langFortran} from '@codemirror/legacy-modes/mode/fortran';
7 import {go as langGo} from '@codemirror/legacy-modes/mode/go';
8 import {haskell as langHaskell} from '@codemirror/legacy-modes/mode/haskell';
9 // import {htmlmixed as langHtmlmixed} from '@codemirror/legacy-modes/mode/htmlmixed';
10 import {javascript as langJavascript} from '@codemirror/legacy-modes/mode/javascript';
11 import {julia as langJulia} from '@codemirror/legacy-modes/mode/julia';
12 import {lua as langLua} from '@codemirror/legacy-modes/mode/lua';
13 // import {markdown as langMarkdown} from '@codemirror/legacy-modes/mode/markdown';
14 import {oCaml as langMllike} from '@codemirror/legacy-modes/mode/mllike';
15 import {nginx as langNginx} from '@codemirror/legacy-modes/mode/nginx';
16 import {perl as langPerl} from '@codemirror/legacy-modes/mode/perl';
17 import {pascal as langPascal} from '@codemirror/legacy-modes/mode/pascal';
18 // import {php as langPhp} from '@codemirror/legacy-modes/mode/php';
19 import {powerShell as langPowershell} from '@codemirror/legacy-modes/mode/powershell';
20 import {properties as langProperties} from '@codemirror/legacy-modes/mode/properties';
21 import {python as langPython} from '@codemirror/legacy-modes/mode/python';
22 import {ruby as langRuby} from '@codemirror/legacy-modes/mode/ruby';
23 import {rust as langRust} from '@codemirror/legacy-modes/mode/rust';
24 import {shell as langShell} from '@codemirror/legacy-modes/mode/shell';
25 import {sql as langSql} from '@codemirror/legacy-modes/mode/sql';
26 import {stex as langStex} from '@codemirror/legacy-modes/mode/stex';
27 import {toml as langToml} from '@codemirror/legacy-modes/mode/toml';
28 import {vb as langVb} from '@codemirror/legacy-modes/mode/vb';
29 import {vbScript as langVbscript} from '@codemirror/legacy-modes/mode/vbscript';
30 import {xml as langXml} from '@codemirror/legacy-modes/mode/xml';
31 import {yaml as langYaml} from '@codemirror/legacy-modes/mode/yaml';
32
33 export const modes = [
34     langCss,
35     langClike,
36     langDiff,
37     langFortran,
38     langGo,
39     langHaskell,
40     // langHtmlmixed,
41     langJavascript,
42     langJulia,
43     langLua,
44     // langMarkdown,
45     langMllike,
46     langNginx,
47     langPerl,
48     langPascal,
49     // langPhp,
50     langPowershell,
51     langProperties,
52     langPython,
53     langRuby,
54     langRust,
55     langShell,
56     langSql,
57     langStex,
58     langToml,
59     langVb,
60     langVbscript,
61     langXml,
62     langYaml,
63 ];
64
65 // Mapping of possible languages or formats from user input to their codemirror modes.
66 // Value can be a mode string or a function that will receive the code content & return the mode string.
67 // The function option is used in the event the exact mode could be dynamic depending on the code.
68 export const modeMap = {
69     bash: 'shell',
70     css: 'css',
71     c: 'text/x-csrc',
72     java: 'text/x-java',
73     scala: 'text/x-scala',
74     kotlin: 'text/x-kotlin',
75     'c++': 'text/x-c++src',
76     'c#': 'text/x-csharp',
77     csharp: 'text/x-csharp',
78     diff: 'diff',
79     for: 'fortran',
80     fortran: 'fortran',
81     'f#': 'text/x-fsharp',
82     fsharp: 'text/x-fsharp',
83     go: 'go',
84     haskell: 'haskell',
85     hs: 'haskell',
86     html: 'htmlmixed',
87     ini: 'properties',
88     javascript: 'text/javascript',
89     json: 'application/json',
90     js: 'text/javascript',
91     jl: 'text/x-julia',
92     julia: 'text/x-julia',
93     latex: 'text/x-stex',
94     lua: 'lua',
95     md: 'markdown',
96     mdown: 'markdown',
97     markdown: 'markdown',
98     ml: 'mllike',
99     nginx: 'nginx',
100     perl: 'perl',
101     pl: 'perl',
102     powershell: 'powershell',
103     properties: 'properties',
104     ocaml: 'text/x-ocaml',
105     pascal: 'text/x-pascal',
106     pas: 'text/x-pascal',
107     php: (content) => {
108         return content.includes('<?php') ? 'php' : 'text/x-php';
109     },
110     py: 'python',
111     python: 'python',
112     ruby: 'ruby',
113     rust: 'rust',
114     rb: 'ruby',
115     rs: 'rust',
116     shell: 'shell',
117     sh: 'shell',
118     stext: 'text/x-stex',
119     toml: 'toml',
120     ts: 'text/typescript',
121     typescript: 'text/typescript',
122     sql: 'text/x-sql',
123     vbs: 'vbscript',
124     vbscript: 'vbscript',
125     'vb.net': 'text/x-vb',
126     vbnet: 'text/x-vb',
127     xml: 'xml',
128     yaml: 'yaml',
129     yml: 'yaml',
130 };
131
132 export function modesAsStreamLanguages() {
133     return modes.map(mode => StreamLanguage.define(mode));
134 }