Skip to content

Commit dbb9de9

Browse files
committed
juptyer: cells with only text/markdown display get output: asis
1 parent c48f29c commit dbb9de9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/core/jupyter/display-data.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ import {
1919
kTextPlain,
2020
} from "../mime.ts";
2121
import {
22+
JupyterCell,
2223
JupyterOutput,
2324
JupyterOutputDisplayData,
2425
JupyterToMarkdownOptions,
2526
} from "./types.ts";
2627

27-
export function isDisplayData(output: JupyterOutput) {
28+
export function isDisplayData(
29+
output: JupyterOutput,
30+
): output is JupyterOutputDisplayData {
2831
return ["display_data", "execute_result"].includes(output.output_type);
2932
}
3033

@@ -139,3 +142,21 @@ export function displayDataIsJson(mimeType: string) {
139142
export function displayDataIsJavascript(mimeType: string) {
140143
return [kApplicationJavascript].includes(mimeType);
141144
}
145+
146+
export function cellHasOnlyMarkdownDisplayData(
147+
cell: JupyterCell,
148+
options: JupyterToMarkdownOptions,
149+
) {
150+
if (cell.outputs) {
151+
return cell.outputs.every((output) => {
152+
if (isDisplayData(output)) {
153+
const mimeType = displayDataMimeType(output, options);
154+
return mimeType && displayDataIsMarkdown(mimeType);
155+
} else {
156+
return false;
157+
}
158+
});
159+
} else {
160+
return false;
161+
}
162+
}

src/core/jupyter/jupyter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
shouldLabelOutputContainer,
5252
} from "./labels.ts";
5353
import {
54+
cellHasOnlyMarkdownDisplayData,
5455
displayDataIsHtml,
5556
displayDataIsImage,
5657
displayDataIsJavascript,
@@ -926,7 +927,9 @@ async function mdFromCodeCell(
926927
cell.options[kOutput] === "asis" ||
927928
// specified globally with no output override for this cell
928929
(options.execute[kOutput] === "asis" &&
929-
cell.options[kOutput] === undefined);
930+
cell.options[kOutput] === undefined) ||
931+
// cell has only markdown display data
932+
cellHasOnlyMarkdownDisplayData(cell, options);
930933

931934
// markdown to return
932935
const md: string[] = [];

0 commit comments

Comments
 (0)