(output: NotebookCellOutput)
| 450 | } |
| 451 | } |
| 452 | function convertStreamOutput(output: NotebookCellOutput): JupyterOutput { |
| 453 | const outputs: string[] = []; |
| 454 | output.items |
| 455 | .filter((opit) => opit.mime === CellOutputMimeTypes.stderr || opit.mime === CellOutputMimeTypes.stdout) |
| 456 | .map((opit) => textDecoder.decode(opit.data)) |
| 457 | .forEach((value) => { |
| 458 | // Ensure each line is a seprate entry in an array (ending with \n). |
| 459 | const lines = value.split('\n'); |
| 460 | // If the last item in `outputs` is not empty and the first item in `lines` is not empty, then concate them. |
| 461 | // As they are part of the same line. |
| 462 | if (outputs.length && lines.length && lines[0].length > 0) { |
| 463 | outputs[outputs.length - 1] = `${outputs[outputs.length - 1]}${lines.shift()!}`; |
| 464 | } |
| 465 | for (const line of lines) { |
| 466 | outputs.push(line); |
| 467 | } |
| 468 | }); |
| 469 | |
| 470 | for (let index = 0; index < outputs.length - 1; index++) { |
| 471 | outputs[index] = `${outputs[index]}\n`; |
| 472 | } |
| 473 | |
| 474 | // Skip last one if empty (it's the only one that could be length 0) |
| 475 | if (outputs.length && outputs[outputs.length - 1].length === 0) { |
| 476 | outputs.pop(); |
| 477 | } |
| 478 | |
| 479 | const streamType = getOutputStreamType(output) || 'stdout'; |
| 480 | |
| 481 | return { |
| 482 | output_type: 'stream', |
| 483 | name: streamType, |
| 484 | text: outputs |
| 485 | }; |
| 486 | } |
| 487 | export function translateCellDisplayOutput(output: NotebookCellOutput): JupyterOutput { |
| 488 | const customMetadata = output.metadata as CellOutputMetadata | undefined; |
| 489 | let result: JupyterOutput; |
no test coverage detected