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

Function isMarimoContent

packages/convert/src/format-detection.ts:6–50  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

4
5/** Check if file content is Marimo format */
6export function isMarimoContent(content: string): boolean {
7 // Marimo notebooks have a marimo import at the file level and @app.cell decorators
8 // Skip shebangs, encoding comments, and module docstrings to find the first significant line
9 const lines = content.split('\n')
10 let inDocstring = false
11 let docstringQuote = ''
12
13 const firstSignificant = lines.find(line => {
14 const t = line.trim()
15 if (t.length === 0) {
16 return false
17 }
18 if (t.startsWith('#!') || /^#\s*(-\*-\s*)?(coding|encoding)[:=]/i.test(t)) {
19 return false
20 }
21
22 // Track module docstring (similar to isPercentContent)
23 for (const q of ['"""', "'''"]) {
24 if (!inDocstring && t.startsWith(q)) {
25 // Check for single-line docstring (starts and ends with same quote)
26 if (t.length > 3 && t.endsWith(q)) {
27 // Single-line docstring, skip this line entirely
28 return false
29 }
30 inDocstring = true
31 docstringQuote = q
32 return false
33 }
34 if (inDocstring && docstringQuote === q && t.includes(q)) {
35 inDocstring = false
36 return false
37 }
38 }
39 if (inDocstring) {
40 return false
41 }
42 return true
43 })
44
45 // Accept both 'import marimo' and 'from marimo import ...'
46 const firstLine = firstSignificant ?? ''
47 const isMarimoImport = /^import\s+marimo\b/.test(firstLine) || /^from\s+marimo\s+import\b/.test(firstLine)
48
49 return isMarimoImport && /@app\.cell\b/.test(content)
50}
51
52/** Check if file content is percent format */
53export function isPercentContent(content: string): boolean {

Callers 4

classifyPyFileFunction · 0.90
convertFunction · 0.90
detectFormatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected