(text, fallback = '')
| 394 | } |
| 395 | |
| 396 | function 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 | |
| 420 | function makeTextSection(text, label = '') { |
| 421 | return { type: 'text', label, text: String(text || '').trim() }; |
no test coverage detected