MCPcopy Create free account
hub / github.com/microsoft/Webwright / inferCodeLanguage

Function inferCodeLanguage

assets/compare_trajectory/app.js:396–418  ·  view source on GitHub ↗
(text, fallback = '')

Source from the content-addressed store, hash-verified

394}
395
396function inferCodeLanguage(text, fallback = '') {
397 const normalizedFallback = normalizeCodeLanguage(fallback);
398 const source = String(text || '').trim();
399 if (!source) {
400 return normalizedFallback || 'plaintext';
401 }
402 if (normalizedFallback) {
403 return normalizedFallback;
404 }
405 if (/^\*\*\* Begin Patch/m.test(source) || /^\*\*\* (Add|Update|Delete) File:/m.test(source)) {
406 return 'diff';
407 }
408 if (looksLikePython(source)) {
409 return 'python';
410 }
411 if (safeJsonParse(source) !== null) {
412 return 'json';
413 }
414 if (looksLikeShell(source)) {
415 return 'bash';
416 }
417 return 'plaintext';
418}
419
420function makeTextSection(text, label = '') {
421 return { type: 'text', label, text: String(text || '').trim() };

Callers 4

makeCodeSectionFunction · 0.85
buildCommandSectionsFunction · 0.85
normalizeCodexFunction · 0.85
normalizeTrajectoryFunction · 0.85

Calls 4

normalizeCodeLanguageFunction · 0.85
looksLikePythonFunction · 0.85
safeJsonParseFunction · 0.85
looksLikeShellFunction · 0.85

Tested by

no test coverage detected