(block: DeepnoteBlock)
| 122 | } |
| 123 | |
| 124 | function convertBlockToCell(block: DeepnoteBlock): PercentCell { |
| 125 | const isMarkdown = isMarkdownBlockType(block.type) |
| 126 | |
| 127 | let content: string |
| 128 | if (isMarkdown) { |
| 129 | try { |
| 130 | content = createMarkdown(block) |
| 131 | } catch { |
| 132 | // Fallback to raw content for unsupported markdown block types |
| 133 | content = block.content || '' |
| 134 | } |
| 135 | } else if (block.type === 'code') { |
| 136 | content = block.content || '' |
| 137 | } else { |
| 138 | // For SQL, visualization, input blocks, etc., generate Python code |
| 139 | try { |
| 140 | content = createPythonCode(block) |
| 141 | } catch { |
| 142 | // Fallback to raw content for unsupported code block types |
| 143 | content = block.content || '' |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Extract title and tags from metadata if present |
| 148 | const title = block.metadata?.title as string | undefined |
| 149 | const tags = block.metadata?.tags as string[] | undefined |
| 150 | |
| 151 | // Restore original cell type if it was a raw cell |
| 152 | const percentCellType = block.metadata?.percent_cell_type as string | undefined |
| 153 | const cellType: 'code' | 'markdown' | 'raw' = percentCellType === 'raw' ? 'raw' : isMarkdown ? 'markdown' : 'code' |
| 154 | |
| 155 | return { |
| 156 | cellType, |
| 157 | content, |
| 158 | ...(title ? { title } : {}), |
| 159 | ...(tags && tags.length > 0 ? { tags } : {}), |
| 160 | } |
| 161 | } |
no test coverage detected