Skip to content

Commit 7776afe

Browse files
authored
Bugfix/issue 3896 (#3910)
* only check contents if length > 0. Closes #3896
1 parent a20856b commit 7776afe

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

news/changelog-1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Jupyter Notebooks
44

55
- Add support for embedding cell outputs in quarto documents using `{{< embed >}}`. You can address cells by Id, Tag, or label, such as `{{< embed mynotebook.ipynb#fig-output >}}` which would embed the output of a cell with the label `fig-output`). You can also provide a list of ids like `{{< embed mynotebook.ipynb#fig-output,tbl-out >}}`.
6+
- Only attempt to postprocess `text/plain` output if it's nonempty ([#3896](https://github.com/quarto-dev/quarto-cli/issues/3896)).
67

78
## Code Annotation
89

src/core/jupyter/jupyter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,9 @@ async function mdFromCodeCell(
10611061
if (output.output_type === "execute_result") {
10621062
const textPlain = (output as JupyterOutputDisplayData).data
10631063
?.[kTextPlain] as string[] | undefined;
1064-
if (textPlain && textPlain[0].startsWith("[<matplotlib")) {
1064+
if (
1065+
textPlain && textPlain.length && textPlain[0].startsWith("[<matplotlib")
1066+
) {
10651067
return false;
10661068
}
10671069
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "raw",
5+
"id": "dbd7953c",
6+
"metadata": {},
7+
"source": [
8+
"---\n",
9+
"title: Some title\n",
10+
"author: Some name\n",
11+
"date: '2022-01-09'\n",
12+
"format:\n",
13+
" html:\n",
14+
" toc: true\n",
15+
" toc-depth: 2\n",
16+
" code-fold: true\n",
17+
" self-contained: true\n",
18+
"---"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 15,
24+
"id": "54f3e4bb",
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"data": {
29+
"text/plain": []
30+
},
31+
"execution_count": 16,
32+
"metadata": {},
33+
"output_type": "execute_result"
34+
},
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"┌─────────┬─────────┬────────┬────────┐\n",
40+
"\u001b[1m \u001b[0m│\u001b[1m cv_elpd \u001b[0m│\u001b[1m cv_avg \u001b[0m│\u001b[1m weight \u001b[0m│\n",
41+
"├─────────┼─────────┼────────┼────────┤\n",
42+
"\u001b[1m model_2 \u001b[0m│ 0.00 │ 0.00 │ 0.79 │\n",
43+
"\u001b[1m model_3 \u001b[0m│ -1.51 │ -0.01 │ 0.18 │\n",
44+
"\u001b[1m model_1 \u001b[0m│ -3.28 │ -0.02 │ 0.03 │\n",
45+
"\u001b[1m model_4 \u001b[0m│ -13.14 │ -0.07 │ 0.00 │\n",
46+
"└─────────┴─────────┴────────┴────────┘\n"
47+
]
48+
}
49+
],
50+
"source": [
51+
"loo_compare(loo_model1, loo_model2, loo_model3, loo_model4)\n",
52+
"# Past results\n",
53+
"# ┌─────────┬─────────┬────────┬────────┐\n",
54+
"# │ │ cv_elpd │ cv_avg │ weight │\n",
55+
"# ├─────────┼─────────┼────────┼────────┤\n",
56+
"# │ model_2 │ 0.00 │ 0.00 │ 0.84 │\n",
57+
"# │ model_3 │ -1.77 │ -0.01 │ 0.14 │\n",
58+
"# │ model_1 │ -3.70 │ -0.02 │ 0.02 │\n",
59+
"# │ model_4 │ -13.94 │ -0.07 │ 0.00 │\n",
60+
"# └─────────┴─────────┴────────┴────────┘"
61+
]
62+
}
63+
],
64+
"metadata": {
65+
"kernelspec": {
66+
"display_name": "julia6 1.8.4",
67+
"language": "julia",
68+
"name": "julia6-1.8"
69+
},
70+
"language_info": {
71+
"file_extension": ".jl",
72+
"mimetype": "application/julia",
73+
"name": "julia",
74+
"version": "1.8.4"
75+
}
76+
},
77+
"nbformat": 4,
78+
"nbformat_minor": 5
79+
}

tests/smoke/smoke-all.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
} from "../verify.ts";
2727
import { readYamlFromMarkdown } from "../../src/core/yaml.ts";
2828
import { outputForInput } from "../utils.ts";
29+
import { jupyterToMarkdown } from "../../src/core/jupyter/jupyter.ts";
30+
import { jupyterNotebookToMarkdown } from "../../src/command/convert/jupyter.ts";
2931

3032
async function fullInit() {
3133
await initYamlIntelligenceResourcesFromFilesystem();
@@ -119,7 +121,7 @@ function resolveTestSpecs(
119121
const globOutput = Deno.args.length
120122
? expandGlobSync(Deno.args[0])
121123
: expandGlobSync(
122-
"docs/smoke-all/**/*.qmd",
124+
"docs/smoke-all/**/*.{qmd,ipynb}",
123125
);
124126

125127
await initYamlIntelligenceResourcesFromFilesystem();
@@ -129,7 +131,9 @@ for (
129131
) {
130132
const input = fileName;
131133

132-
const metadata = readYamlFromMarkdown(Deno.readTextFileSync(input));
134+
const metadata = input.endsWith("qmd")
135+
? readYamlFromMarkdown(Deno.readTextFileSync(input))
136+
: readYamlFromMarkdown(await jupyterNotebookToMarkdown(input, false));
133137
const testSpecs = [];
134138

135139
if (hasTestSpecs(metadata)) {

0 commit comments

Comments
 (0)