detectLanguage function
Language detection from file extension or code fence.
Implementation
String detectLanguage(String hint) {
final lower = hint.toLowerCase().trim();
return switch (lower) {
'js' || 'jsx' || 'javascript' => 'javascript',
'ts' || 'tsx' || 'typescript' => 'typescript',
'dart' => 'dart',
'py' || 'python' => 'python',
'rb' || 'ruby' => 'ruby',
'rs' || 'rust' => 'rust',
'go' || 'golang' => 'go',
'java' => 'java',
'kt' || 'kotlin' => 'kotlin',
'swift' => 'swift',
'c' || 'h' => 'c',
'cpp' || 'cc' || 'cxx' || 'hpp' => 'cpp',
'cs' || 'csharp' => 'csharp',
'php' => 'php',
'sh' || 'bash' || 'zsh' || 'shell' => 'shell',
'sql' => 'sql',
'html' || 'htm' => 'html',
'css' || 'scss' || 'sass' => 'css',
'json' => 'json',
'yaml' || 'yml' => 'yaml',
'xml' => 'xml',
'md' || 'markdown' => 'markdown',
'toml' => 'toml',
'dockerfile' => 'dockerfile',
_ => 'plaintext',
};
}