* Get label for a code block - prefer first comment, fall back to first line.
(content: string)
| 66 | * Get label for a code block - prefer first comment, fall back to first line. |
| 67 | */ |
| 68 | function getCodeBlockLabel(content: string): string { |
| 69 | const lines = content.split('\n') |
| 70 | |
| 71 | // Look for first comment line (Python style) |
| 72 | for (const line of lines) { |
| 73 | const trimmed = line.trim() |
| 74 | if (trimmed.startsWith('#') && !trimmed.startsWith('#!')) { |
| 75 | // Found a comment, use it as label |
| 76 | return truncate(trimmed, MAX_LABEL_LENGTH) |
| 77 | } |
| 78 | // Stop looking after first non-empty, non-comment line |
| 79 | if (trimmed && !trimmed.startsWith('#')) { |
| 80 | break |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // No comment found, use first non-empty line (skip shebangs) |
| 85 | for (const line of lines) { |
| 86 | const trimmed = line.trim() |
| 87 | if (trimmed.startsWith('#!')) { |
| 88 | continue |
| 89 | } |
| 90 | if (trimmed) { |
| 91 | return truncate(trimmed, MAX_LABEL_LENGTH) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return 'code (empty)' |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get label for a SQL block - show first meaningful line. |
no test coverage detected