(content: string)
| 4 | |
| 5 | /** Check if file content is Marimo format */ |
| 6 | export 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 */ |
| 53 | export function isPercentContent(content: string): boolean { |
no outgoing calls
no test coverage detected