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

@@ -74,7 +74,6 @@ impl PluginHandle {
} }
pub async fn set_boot_response(&self, resp: &BootResponse) { pub async fn set_boot_response(&self, resp: &BootResponse) {
info!("BOOTED PLUGIN {:?}", resp);
let mut boot_resp = self.boot_resp.lock().await; let mut boot_resp = self.boot_resp.lock().await;
*boot_resp = resp.clone(); *boot_resp = resp.clone();
} }

View File

@@ -25,14 +25,17 @@ function detectFromContent(
): EditorProps['language'] { ): EditorProps['language'] {
if (content == null) return 'text'; 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'; return 'json';
} else if ( } else if (
content.toLowerCase().startsWith('<!doctype') || firstBytes.toLowerCase().startsWith('<!doctype') ||
content.toLowerCase().startsWith('<html') firstBytes.toLowerCase().startsWith('<html')
) { ) {
return 'html'; return 'html';
} else if (content.startsWith('<')) { } else if (firstBytes.startsWith('<')) {
return 'xml'; return 'xml';
} }