MCPcopy Index your code
hub / github.com/deepnote/deepnote / getCodeBlockLabel

Function getCodeBlockLabel

packages/cli/src/utils/block-label.ts:68–96  ·  view source on GitHub ↗

* Get label for a code block - prefer first comment, fall back to first line.

(content: string)

Source from the content-addressed store, hash-verified

66 * Get label for a code block - prefer first comment, fall back to first line.
67 */
68function 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.

Callers 1

getBlockLabelFunction · 0.85

Calls 1

truncateFunction · 0.85

Tested by

no test coverage detected