(content: string)
| 51 | |
| 52 | /** Check if file content is percent format */ |
| 53 | export function isPercentContent(content: string): boolean { |
| 54 | // Percent format files have '# %%' cell markers at the start of lines |
| 55 | // We need to check that the marker is not inside a triple-quoted string |
| 56 | // (e.g., module docstrings at the beginning of the file) |
| 57 | const lines = content.split('\n') |
| 58 | let inTripleQuote = false |
| 59 | let quoteChar = '' |
| 60 | |
| 61 | for (const line of lines) { |
| 62 | // Check for triple quote toggles |
| 63 | for (const q of ['"""', "'''"]) { |
| 64 | let idx = line.indexOf(q, 0) |
| 65 | while (idx !== -1) { |
| 66 | if (!inTripleQuote) { |
| 67 | inTripleQuote = true |
| 68 | quoteChar = q |
| 69 | } else if (quoteChar === q) { |
| 70 | inTripleQuote = false |
| 71 | } |
| 72 | idx = line.indexOf(q, idx + 3) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Check for cell marker outside triple quotes |
| 77 | if (!inTripleQuote && /^# %%/.test(line)) { |
| 78 | return true |
| 79 | } |
| 80 | } |
| 81 | return false |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Detects the notebook format from filename and optionally content. |
no outgoing calls
no test coverage detected