The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import "@t3tools/client-runtime/assembly-highlighting"; |
| 2 | import { |
| 3 | getFiletypeFromFileName, |
| 4 | setCustomExtension, |
| 5 | } from "@pierre/diffs/utils/getFiletypeFromFileName"; |
| 6 | |
| 7 | import { HIGHLIGHTS_LANGUAGE_IDS } from "./highlights.generated"; |
| 8 | |
| 9 | // Highlights has no lexer for these dialects, so they use their base language's. |
| 10 | setCustomExtension("luau", "lua"); |
| 11 | setCustomExtension("xsl", "xml"); |
| 12 | setCustomExtension("xslt", "xml"); |
| 13 | |
| 14 | /** The native lexer ID for a @pierre/highlights language name, or 0 (plain text). */ |
| 15 | export function highlightLanguageId(language: string): number { |
| 16 | return Object.hasOwn(HIGHLIGHTS_LANGUAGE_IDS, language) ? HIGHLIGHTS_LANGUAGE_IDS[language]! : 0; |
| 17 | } |
| 18 | |
| 19 | /** A @pierre/highlights language for a fence language or file path, or `text`. */ |
| 20 | export function resolveHighlightLanguage(input: { |
| 21 | readonly language?: string | null; |
| 22 | readonly path?: string; |
| 23 | }): string { |
| 24 | const hinted = input.language?.trim().toLowerCase(); |
| 25 | if (hinted && highlightLanguageId(hinted) !== 0) return hinted; |
| 26 | const detected = input.path ? getFiletypeFromFileName(input.path)?.toLowerCase() : undefined; |
| 27 | if (detected && highlightLanguageId(detected) !== 0) return detected; |
| 28 | return "text"; |
| 29 | } |