( cells: PythonCell[], scriptName: string = 'DataKit_Script' )
| 262 | * Export notebook cells as plain Python script |
| 263 | */ |
| 264 | export const exportAsPythonScript = ( |
| 265 | cells: PythonCell[], |
| 266 | scriptName: string = 'DataKit_Script' |
| 267 | ): void => { |
| 268 | try { |
| 269 | const pythonContent = cells |
| 270 | .filter(cell => cell.type === 'code') |
| 271 | .map((cell, index) => { |
| 272 | const cellComment = `# Cell ${index + 1}\n`; |
| 273 | return cellComment + cell.code; |
| 274 | }) |
| 275 | .join('\n\n'); |
| 276 | |
| 277 | const blob = new Blob([pythonContent], { type: 'text/plain' }); |
| 278 | const url = URL.createObjectURL(blob); |
| 279 | const a = document.createElement('a'); |
| 280 | a.href = url; |
| 281 | a.download = `${scriptName}.py`; |
| 282 | document.body.appendChild(a); |
| 283 | a.click(); |
| 284 | document.body.removeChild(a); |
| 285 | URL.revokeObjectURL(url); |
| 286 | |
| 287 | } catch (error) { |
| 288 | console.error('Failed to export Python script:', error); |
| 289 | throw new Error('Python script export failed. Please try again.'); |
| 290 | } |
| 291 | }; |
| 292 | |
| 293 | /** |
| 294 | * Export notebook cells as Markdown document |
nothing calls this directly
no outgoing calls
no test coverage detected