Ignore whitespace during content type detection

This commit is contained in:
Gregory Schier
2025-03-06 06:22:21 -08:00
parent 6b7c144a11
commit 26371e5f6b
2 changed files with 7 additions and 5 deletions

View File

@@ -25,14 +25,17 @@ function detectFromContent(
): EditorProps['language'] {
if (content == null) return 'text';
if (content.startsWith('{') || content.startsWith('[')) {
const firstBytes = content.slice(0, 20).trim();
console.log("FIRST BYTES", firstBytes);
if (firstBytes.startsWith('{') || firstBytes.startsWith('[')) {
return 'json';
} else if (
content.toLowerCase().startsWith('<!doctype') ||
content.toLowerCase().startsWith('<html')
firstBytes.toLowerCase().startsWith('<!doctype') ||
firstBytes.toLowerCase().startsWith('<html')
) {
return 'html';
} else if (content.startsWith('<')) {
} else if (firstBytes.startsWith('<')) {
return 'xml';
}