(cells: PythonCell[])
| 174 | * Generate HTML content for PDF export from notebook cells |
| 175 | */ |
| 176 | const generateNotebookHTML = (cells: PythonCell[]): string => { |
| 177 | const cellsHTML = cells.map((cell, index) => { |
| 178 | let cellHTML = ` |
| 179 | <div style="${pdfStyles.cellContainer}"> |
| 180 | <div style="${pdfStyles.cellHeader}"> |
| 181 | ${cell.type === 'code' ? 'Code' : 'Markdown'} Cell [${index + 1}] |
| 182 | </div> |
| 183 | <div style="${pdfStyles.cellContent}"> |
| 184 | `; |
| 185 | |
| 186 | if (cell.type === 'markdown') { |
| 187 | // Render markdown as HTML |
| 188 | cellHTML += convertMarkdownToHTML(cell.code); |
| 189 | } else { |
| 190 | // Render code with syntax highlighting |
| 191 | cellHTML += ` |
| 192 | <pre style="${pdfStyles.codeBlock}">${cell.code}</pre> |
| 193 | `; |
| 194 | |
| 195 | // Add outputs if they exist |
| 196 | if (cell.output.length > 0) { |
| 197 | cellHTML += ` |
| 198 | <div style="font-weight: bold; margin-top: 10px; margin-bottom: 5px; font-size: 12px;"> |
| 199 | Output: |
| 200 | </div> |
| 201 | <div style="${pdfStyles.outputBlock}"> |
| 202 | `; |
| 203 | |
| 204 | cell.output.forEach(output => { |
| 205 | if (output.type === 'error') { |
| 206 | cellHTML += ` |
| 207 | <div style="color: #d32f2f; font-weight: bold; margin-bottom: 5px; font-size: 11px; font-family: Consolas, Monaco, monospace;"> |
| 208 | ${output.content} |
| 209 | </div> |
| 210 | `; |
| 211 | } else if (output.type === 'image') { |
| 212 | cellHTML += ` |
| 213 | <img src="${output.content}" style="max-width: 100%; height: auto; border: 1px solid #ccc; border-radius: 4px;" /> |
| 214 | `; |
| 215 | } else { |
| 216 | cellHTML += ` |
| 217 | <div style="color: #333333; white-space: pre-wrap; margin-bottom: 5px; font-size: 11px; font-family: Consolas, Monaco, monospace;"> |
| 218 | ${output.content} |
| 219 | </div> |
| 220 | `; |
| 221 | } |
| 222 | }); |
| 223 | |
| 224 | cellHTML += '</div>'; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | cellHTML += ` |
| 229 | </div> |
| 230 | </div> |
| 231 | `; |
| 232 | |
| 233 | return cellHTML; |
no test coverage detected