/** file → grammar classification, shared by highlighting and the per-language file listing */ import languages from "./languages.json" with { type: "json" }; const filenames = new Map(Object.entries(languages.filenames)); const aliases = new Map(Object.entries(languages.aliases)); /** mirrors detect() in src/grammar_manifest.rs: by file name, then by extension */ export function detectLanguage(path: string): string | null { const name = path.split(/[/\\]/).at(-1)!.toLowerCase(); return filenames.get(name) ?? aliases.get(name) ?? aliases.get(name.split(".").at(-1)!) ?? null; } /** mirrors group() in src/languages.rs; keep them in sync */ export const languageGroup = (grammar: string) => grammar === "tsx" ? "typescript" : grammar;