mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 23:19:39 +02:00
Fix content type detection
This commit is contained in:
@@ -10,19 +10,18 @@ export function languageFromContentType(
|
|||||||
} else if (justContentType.includes('xml')) {
|
} else if (justContentType.includes('xml')) {
|
||||||
return 'xml';
|
return 'xml';
|
||||||
} else if (justContentType.includes('html')) {
|
} else if (justContentType.includes('html')) {
|
||||||
return detectFromContent(content);
|
return detectFromContent(content, 'html');
|
||||||
} else if (justContentType.includes('javascript')) {
|
} else if (justContentType.includes('javascript')) {
|
||||||
return 'javascript';
|
return 'javascript';
|
||||||
}
|
}
|
||||||
|
|
||||||
return detectFromContent(content);
|
return detectFromContent(content, 'text');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isJSON(text: string): boolean {
|
function detectFromContent(
|
||||||
return text.startsWith('{') || text.startsWith('[');
|
content: string | null,
|
||||||
}
|
fallback: EditorProps['language'],
|
||||||
|
): EditorProps['language'] {
|
||||||
function detectFromContent(content: string | null): EditorProps['language'] {
|
|
||||||
if (content == null) return 'text';
|
if (content == null) return 'text';
|
||||||
|
|
||||||
if (content.startsWith('{') || content.startsWith('[')) {
|
if (content.startsWith('{') || content.startsWith('[')) {
|
||||||
@@ -30,5 +29,6 @@ function detectFromContent(content: string | null): EditorProps['language'] {
|
|||||||
} else if (content.startsWith('<!DOCTYPE') || content.startsWith('<html')) {
|
} else if (content.startsWith('<!DOCTYPE') || content.startsWith('<html')) {
|
||||||
return 'html';
|
return 'html';
|
||||||
}
|
}
|
||||||
return 'text';
|
|
||||||
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user