Skip to content
File

Blob: src/shared/editor/schema/code-block-model.ts

typescript40 lines
1// Runtime-safe code block metadata used by both editor extensions and static presentation.
2// Keep this file free of Tiptap imports so public Sites islands can use it.
3 
4// Keep Plain Text first and the remaining languages sorted A-Z by display name.
5export const CODE_LANGUAGES: Record<string, { name: string; aliases?: string[] }> = {
6 text: { name: "Plain Text", aliases: ["plaintext", "txt"] },
7 c: { name: "C", aliases: ["h"] },
8 csharp: { name: "C#", aliases: ["cs", "c#"] },
9 cpp: { name: "C++", aliases: ["cxx", "cc", "hpp"] },
10 dockerfile: { name: "Dockerfile", aliases: ["docker"] },
11 go: { name: "Go" },
12 hcl: { name: "HCL", aliases: ["tf", "terraform"] },
13 java: { name: "Java" },
14 javascript: { name: "JavaScript", aliases: ["js"] },
15 json: { name: "JSON" },
16 jsonc: { name: "JSONC" },
17 markdown: { name: "Markdown", aliases: ["md"] },
18 php: { name: "PHP" },
19 python: { name: "Python", aliases: ["py"] },
20 rust: { name: "Rust" },
21 shell: { name: "Shell", aliases: ["sh", "bash", "shell", "zsh"] },
22 sql: { name: "SQL" },
23 toml: { name: "TOML" },
24 typescript: { name: "TypeScript", aliases: ["ts"] },
25 yaml: { name: "YAML", aliases: ["yml"] },
26};
27 
28const ALIAS_TO_LANG: Record<string, string> = {};
29for (const [id, meta] of Object.entries(CODE_LANGUAGES)) {
30 ALIAS_TO_LANG[id] = id;
31 for (const alias of meta.aliases ?? []) {
32 ALIAS_TO_LANG[alias] = id;
33 }
34}
35 
36export function resolveLanguage(raw: string | undefined | null): string {
37 if (!raw) return "text";
38 return ALIAS_TO_LANG[raw.trim().toLowerCase()] ?? "text";
39}