File size: 2,774 Bytes
0bd62e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
import type { Extension } from "@codemirror/state";
import { StreamLanguage } from "@codemirror/language";
import { sql } from "@codemirror/legacy-modes/mode/sql";
import { _ } from "svelte-i18n";
const possible_langs = [
"python",
"c",
"cpp",
"markdown",
"json",
"html",
"css",
"javascript",
"typescript",
"yaml",
"dockerfile",
"shell",
"r",
"sql"
];
const sql_dialects = [
"standardSQL",
"msSQL",
"mySQL",
"mariaDB",
"sqlite",
"cassandra",
"plSQL",
"hive",
"pgSQL",
"gql",
"gpSQL",
"sparkSQL",
"esper"
] as const;
const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
python: () => import("@codemirror/lang-python").then((m) => m.python()),
c: () =>
import("@codemirror/legacy-modes/mode/clike").then((m) =>
StreamLanguage.define(m.c)
),
cpp: () =>
import("@codemirror/legacy-modes/mode/clike").then((m) =>
StreamLanguage.define(m.cpp)
),
markdown: async () => {
const [md, frontmatter] = await Promise.all([
import("@codemirror/lang-markdown"),
import("./frontmatter")
]);
return md.markdown({ extensions: [frontmatter.frontmatter] });
},
json: () => import("@codemirror/lang-json").then((m) => m.json()),
html: () => import("@codemirror/lang-html").then((m) => m.html()),
css: () => import("@codemirror/lang-css").then((m) => m.css()),
javascript: () =>
import("@codemirror/lang-javascript").then((m) => m.javascript()),
typescript: () =>
import("@codemirror/lang-javascript").then((m) =>
m.javascript({ typescript: true })
),
yaml: () =>
import("@codemirror/legacy-modes/mode/yaml").then((m) =>
StreamLanguage.define(m.yaml)
),
dockerfile: () =>
import("@codemirror/legacy-modes/mode/dockerfile").then((m) =>
StreamLanguage.define(m.dockerFile)
),
shell: () =>
import("@codemirror/legacy-modes/mode/shell").then((m) =>
StreamLanguage.define(m.shell)
),
r: () =>
import("@codemirror/legacy-modes/mode/r").then((m) =>
StreamLanguage.define(m.r)
),
sql: () =>
import("@codemirror/legacy-modes/mode/sql").then((m) =>
StreamLanguage.define(m.standardSQL)
),
...Object.fromEntries(
sql_dialects.map((dialect) => [
"sql-" + dialect,
() =>
import("@codemirror/legacy-modes/mode/sql").then((m) =>
StreamLanguage.define(m[dialect])
)
])
)
} as const;
const alias_map: Record<string, string> = {
py: "python",
md: "markdown",
js: "javascript",
ts: "typescript",
sh: "shell"
};
export async function getLanguageExtension(
lang: string
): Promise<Extension | undefined> {
const _lang = lang_map[lang] || lang_map[alias_map[lang]] || undefined;
if (_lang) {
return _lang();
}
return undefined;
}
|