Skip to content

Commit 9b762d7

Browse files
committed
allow stream outputs to be string or string[]
1 parent f13fc3d commit 9b762d7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/core/jupyter/jupyter.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,13 @@ async function mdFromCodeCell(
16101610
if (output.output_type === "stream") {
16111611
const stream = output as JupyterOutputStream;
16121612
if (asis && stream.name === "stdout") {
1613-
md.push(stream.text.join(""));
1613+
let text: string[] = [];
1614+
if (typeof stream.text === "string") {
1615+
text = [stream.text];
1616+
} else {
1617+
text = stream.text;
1618+
}
1619+
md.push(text.join(""));
16141620
} else {
16151621
md.push(mdOutputStream(stream));
16161622
}
@@ -1750,21 +1756,28 @@ function isMarkdown(output: JupyterOutput, options: JupyterToMarkdownOptions) {
17501756
}
17511757

17521758
function mdOutputStream(output: JupyterOutputStream) {
1759+
let text: string[] = [];
1760+
if (typeof output.text === "string") {
1761+
text = [output.text];
1762+
} else {
1763+
text = output.text;
1764+
}
1765+
17531766
// trim off warning source line for notebook
17541767
if (output.name === "stderr") {
1755-
if (output.text[0]) {
1756-
const firstLine = output.text[0].replace(
1768+
if (text[0]) {
1769+
const firstLine = text[0].replace(
17571770
/<ipython-input.*?>:\d+:\s+/,
17581771
"",
17591772
);
17601773
return mdCodeOutput(
1761-
[firstLine, ...output.text.slice(1)].map(colors.stripColor),
1774+
[firstLine, ...text.slice(1)].map(colors.stripColor),
17621775
);
17631776
}
17641777
}
17651778

17661779
// normal default handling
1767-
return mdCodeOutput(output.text.map(colors.stripColor));
1780+
return mdCodeOutput(text.map(colors.stripColor));
17681781
}
17691782

17701783
async function mdOutputError(

src/core/jupyter/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ export interface JupyterOutput {
166166
metadata?: Record<string, unknown>;
167167
data?: Record<string, unknown>;
168168
name?: string;
169-
text?: string[];
169+
text?: string[] | string;
170170
}
171171

172172
export interface JupyterOutputStream extends JupyterOutput {
173173
name: "stdout" | "stderr";
174-
text: string[];
174+
text: string[] | string;
175175
}
176176

177177
export interface JupyterOutputDisplayData extends JupyterOutput {

0 commit comments

Comments
 (0)