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

Function convertBlockToCell

packages/convert/src/deepnote-to-marimo.ts:214–264  ·  view source on GitHub ↗
(block: DeepnoteBlock)

Source from the content-addressed store, hash-verified

212}
213
214function convertBlockToCell(block: DeepnoteBlock): MarimoCell {
215 const isMarkdown = isMarkdownBlockType(block.type)
216 const isSql = block.type === 'sql'
217 const metadata = block.metadata || {}
218
219 let content: string
220 let cellType: 'code' | 'markdown' | 'sql'
221
222 if (isMarkdown) {
223 cellType = 'markdown'
224 try {
225 content = createMarkdown(block)
226 } catch {
227 // Fallback to raw content for unsupported markdown block types
228 content = block.content || ''
229 }
230 } else if (isSql) {
231 cellType = 'sql'
232 // For SQL blocks, use the raw SQL query content
233 content = block.content || ''
234 } else if (block.type === 'code') {
235 cellType = 'code'
236 content = block.content || ''
237 } else {
238 cellType = 'code'
239 // For visualization, input blocks, etc., generate Python code
240 try {
241 content = createPythonCode(block)
242 } catch {
243 // Fallback to raw content for unsupported code block types
244 content = block.content || ''
245 }
246 }
247
248 // Extract Marimo-specific metadata
249 const dependencies = metadata.marimo_dependencies as string[] | undefined
250 const exports = metadata.marimo_exports as string[] | undefined
251 const hidden = metadata.is_code_hidden as boolean | undefined
252 const disabled = metadata.marimo_disabled as boolean | undefined
253 const functionName = metadata.marimo_function_name as string | undefined
254
255 return {
256 cellType,
257 content,
258 ...(functionName ? { functionName } : {}),
259 ...(dependencies && dependencies.length > 0 ? { dependencies } : {}),
260 ...(exports && exports.length > 0 ? { exports } : {}),
261 ...(hidden ? { hidden } : {}),
262 ...(disabled ? { disabled } : {}),
263 }
264}
265
266/**
267 * Escapes a string for use in a Python double-quoted string literal.

Callers 1

convertBlocksToMarimoAppFunction · 0.70

Calls 3

isMarkdownBlockTypeFunction · 0.90
createMarkdownFunction · 0.90
createPythonCodeFunction · 0.90

Tested by

no test coverage detected