( cell: MarimoCell, index: number, idGenerator: () => string, outputs?: JupyterOutput[] )
| 501 | } |
| 502 | |
| 503 | function convertCellToBlock( |
| 504 | cell: MarimoCell, |
| 505 | index: number, |
| 506 | idGenerator: () => string, |
| 507 | outputs?: JupyterOutput[] |
| 508 | ): DeepnoteBlock { |
| 509 | let blockType: 'code' | 'markdown' | 'sql' |
| 510 | if (cell.cellType === 'markdown') { |
| 511 | blockType = 'markdown' |
| 512 | } else if (cell.cellType === 'sql') { |
| 513 | blockType = 'sql' |
| 514 | } else { |
| 515 | blockType = 'code' |
| 516 | } |
| 517 | |
| 518 | const metadata: Record<string, unknown> = {} |
| 519 | |
| 520 | // Preserve Marimo-specific info in metadata |
| 521 | if (cell.dependencies && cell.dependencies.length > 0) { |
| 522 | metadata.marimo_dependencies = cell.dependencies |
| 523 | } |
| 524 | if (cell.exports && cell.exports.length > 0) { |
| 525 | metadata.marimo_exports = cell.exports |
| 526 | } |
| 527 | if (cell.hidden) { |
| 528 | metadata.is_code_hidden = true |
| 529 | } |
| 530 | if (cell.disabled) { |
| 531 | metadata.marimo_disabled = true |
| 532 | } |
| 533 | if (cell.functionName && cell.functionName !== '__') { |
| 534 | metadata.marimo_function_name = cell.functionName |
| 535 | } |
| 536 | |
| 537 | // For SQL blocks, set the variable name from exports if available |
| 538 | if (cell.cellType === 'sql' && cell.exports && cell.exports.length > 0) { |
| 539 | metadata.deepnote_variable_name = cell.exports[0] |
| 540 | } |
| 541 | |
| 542 | const block = { |
| 543 | blockGroup: idGenerator(), |
| 544 | content: cell.content, |
| 545 | id: idGenerator(), |
| 546 | metadata: Object.keys(metadata).length > 0 ? metadata : {}, |
| 547 | sortingKey: generateSortingKey(index), |
| 548 | type: blockType, |
| 549 | // Add outputs if available (for code and SQL blocks) |
| 550 | ...(outputs && outputs.length > 0 && (blockType === 'code' || blockType === 'sql') ? { outputs } : {}), |
| 551 | } as DeepnoteBlock |
| 552 | |
| 553 | return block |
| 554 | } |
no test coverage detected