const extensions = {
html: 'markup', htm: 'markup', xml: 'markup', svg: 'markup', vue: 'markup',
css: 'css', js: 'javascript', mjs: 'javascript', cjs: 'javascript', jsx: 'jsx',
ts: 'typescript', mts: 'typescript', cts: 'typescript', tsx: 'tsx',
json: 'json', ipynb: 'json', md: 'markdown', markdown: 'markdown',
py: 'python', pyw: 'python', sh: 'bash', bash: 'bash', zsh: 'bash',
yml: 'yaml', yaml: 'yaml', toml: 'toml', sql: 'sql', csv: 'csv',
c: 'c', h: 'c', cpp: 'cpp', cc: 'cpp', cxx: 'cpp', hpp: 'cpp',
cs: 'csharp', java: 'java', go: 'go', rs: 'rust', diff: 'diff', patch: 'diff',
};
export function editorLanguage(path = '') {
const name = path.split('/').at(-1).toLowerCase();
if (/^dockerfile(?:\.|$)/.test(name)) return 'docker';
if (/^\.(?:bashrc|bash_profile|zshrc|profile)$/.test(name)) return 'bash';
return extensions[name.split('.').at(-1)] ?? null;
}
// Bound both tokenization and the amount of highlighted DOM on the main thread.
export function canHighlight(text) {
if (text.length > 200_000) return false;
let lines = 1;
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10 && ++lines > 5000) return false;
return true;
}