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

Function detectFormat

packages/convert/src/format-detection.ts:88–108  ·  view source on GitHub ↗
(filename: string, content?: string)

Source from the content-addressed store, hash-verified

86 * For .py files, content is required to distinguish between Marimo and Percent formats.
87 */
88export function detectFormat(filename: string, content?: string): NotebookFormat {
89 const lowercaseFilename = filename.toLowerCase()
90
91 if (lowercaseFilename.endsWith('.ipynb')) return 'jupyter'
92 if (lowercaseFilename.endsWith('.deepnote')) return 'deepnote'
93 if (lowercaseFilename.endsWith('.qmd')) return 'quarto'
94
95 if (lowercaseFilename.endsWith('.py')) {
96 if (!content) {
97 throw new UnsupportedFormatError('Content is required to detect format for .py files', { filename })
98 }
99 if (isMarimoContent(content)) return 'marimo'
100 if (isPercentContent(content)) return 'percent'
101 throw new UnsupportedFormatError(
102 'Unsupported Python file format. File must be percent format (# %%) or Marimo (@app.cell).',
103 { filename }
104 )
105 }
106
107 throw new UnsupportedFormatError(`Unsupported file format: ${filename}`, { filename })
108}
109
110/**
111 * Non-throwing variant of {@link detectFormat}.

Callers 5

determineInputFormatFunction · 0.90
parseRunnableFileContentFunction · 0.90
handleConvertToFunction · 0.90
tryDetectFormatFunction · 0.85

Calls 2

isMarimoContentFunction · 0.85
isPercentContentFunction · 0.85

Tested by

no test coverage detected