mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 00:01:22 +02:00
Detect JSON language if application/javascript returns JSON
This commit is contained in:
@@ -11,7 +11,7 @@ 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')) {
|
||||||
const detected = detectFromContent(content, 'html');
|
const detected = detectFromContent(content);
|
||||||
if (detected === 'xml') {
|
if (detected === 'xml') {
|
||||||
// If it's detected as XML, but is already HTML, don't change it
|
// If it's detected as XML, but is already HTML, don't change it
|
||||||
return 'html';
|
return 'html';
|
||||||
@@ -19,7 +19,8 @@ export function languageFromContentType(
|
|||||||
return detected;
|
return detected;
|
||||||
}
|
}
|
||||||
} else if (justContentType.includes('javascript')) {
|
} else if (justContentType.includes('javascript')) {
|
||||||
return 'javascript';
|
// Sometimes `application/javascript` returns JSON, so try detecting that
|
||||||
|
return detectFromContent(content, 'javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
return detectFromContent(content, 'text');
|
return detectFromContent(content, 'text');
|
||||||
@@ -27,7 +28,7 @@ export function languageFromContentType(
|
|||||||
|
|
||||||
function detectFromContent(
|
function detectFromContent(
|
||||||
content: string | null,
|
content: string | null,
|
||||||
fallback: EditorProps['language'],
|
fallback?: EditorProps['language'],
|
||||||
): EditorProps['language'] {
|
): EditorProps['language'] {
|
||||||
if (content == null) return 'text';
|
if (content == null) return 'text';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user