MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / detectLanguage

Function detectLanguage

packages/react/src/components/code-block.tsx:20–27  ·  view source on GitHub ↗
(code: string, hint?: string)

Source from the content-addressed store, hash-verified

18// ---------------------------------------------------------------------------
19
20function detectLanguage(code: string, hint?: string): string {
21 if (hint) return resolveLang(hint) ?? "json";
22 const trimmed = code.trimStart();
23 if (trimmed.startsWith("{") || trimmed.startsWith("[")) return "json";
24 if (trimmed.startsWith("<")) return "xml";
25 if (trimmed.startsWith("---")) return "yaml";
26 return "json";
27}
28
29// ---------------------------------------------------------------------------
30// Icons

Callers 1

CodeBlockFunction · 0.85

Calls 1

resolveLangFunction · 0.90

Tested by

no test coverage detected