Skip to content

Commit c7c7f54

Browse files
authored
Merge pull request #8490 from quarto-dev/bugfix/8472
Embed - Properly emit cell yaml even with `echo` set
2 parents c4dd31f + c12ab14 commit c7c7f54

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

src/core/jupyter/jupyter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ async function mdFromCodeCell(
13861386
const divBeginMd = divMd.join("").replace(/ $/, "").concat("}\n");
13871387

13881388
// write code if appropriate
1389-
if (includeCode(cell, options)) {
1389+
if (includeCode(cell, options) || options.preserveCodeCellYaml) {
13901390
const fenced = echoFenced(cell, options);
13911391
const ticks = "`".repeat(
13921392
Math.max(countTicks(cell.source) + 1, fenced ? 4 : 3),

tests/docs/embed/qmd-embed/index.qmd

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Hi"
3+
---
4+
5+
{{< embed notebook.qmd#fig-index-plot >}}
6+
7+
{{< embed notebook2.qmd#fig-polar echo=true >}}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: "Quarto MWE"
3+
format: html
4+
---
5+
6+
```{python}
7+
#| echo: false
8+
#| label: fig-index-plot
9+
#| fig-cap: "A plot of the sine function"
10+
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
14+
r = np.arange(0, 2, 0.01)
15+
theta = 2 * np.pi * r
16+
fig, ax = plt.subplots(
17+
subplot_kw = {'projection': 'polar'}
18+
)
19+
ax.plot(theta, r)
20+
ax.set_rticks([0.5, 1, 1.5, 2])
21+
ax.grid(True)
22+
plt.show()
23+
```
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "matplotlib demo"
3+
format: html
4+
---
5+
6+
For a demonstration of a line plot on a polar axis, see @fig-polar.
7+
8+
```{python}
9+
#| label: fig-polar
10+
#| fig-cap: "A line plot on a polar axis"
11+
12+
import numpy as np
13+
import matplotlib.pyplot as plt
14+
15+
r = np.arange(0, 2, 0.01)
16+
theta = 2 * np.pi * r
17+
fig, ax = plt.subplots(
18+
subplot_kw = {'projection': 'polar'}
19+
)
20+
ax.plot(theta, r)
21+
ax.set_rticks([0.5, 1, 1.5, 2])
22+
ax.grid(True)
23+
plt.show()
24+
```

tests/smoke/embed/render-embed.test.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*
66
*/
7-
import { dirname, join } from "path/mod.ts";
7+
import { dirname, extname, join } from "path/mod.ts";
88
import { docs, outputForInput } from "../../utils.ts";
99
import {
1010
ensureFileRegexMatches,
@@ -13,6 +13,7 @@ import {
1313
noErrorsOrWarnings,
1414
} from "../../verify.ts";
1515
import { testRender } from "../render/render.ts";
16+
import { walkSync } from "fs/mod.ts";
1617

1718
const format = "html";
1819
const input = docs("embed/embed-qmd.qmd");
@@ -102,3 +103,35 @@ testRender(ipynbInput, format, false, [
102103
return Promise.resolve();
103104
},
104105
});
106+
107+
// Test different echo settings (bug 8472)
108+
const docInput = docs("embed/qmd-embed/index.qmd");
109+
const docOutput = outputForInput(docInput, "html");
110+
testRender(docInput, "html", false, [
111+
noErrorsOrWarnings,
112+
ensureHtmlElements(docOutput.outputPath, [
113+
// Make sure the embeds produce expected output
114+
"#fig-polar",
115+
"#fig-index-plot",
116+
// Make sure notebook links are present
117+
"a.quarto-notebook-link",
118+
".quarto-alternate-notebooks a",
119+
]),
120+
// Ensure the captions look good
121+
ensureFileRegexMatches(docOutput.outputPath, [
122+
/Figure.*1:/,
123+
/Figure.*2:/,
124+
]),
125+
], {
126+
teardown: () => {
127+
// Only qmds should be left in this directory
128+
const dir = join(Deno.cwd(), dirname(docInput));
129+
130+
const cleanup = ["notebook.embed_files", "notebook.embed-preview.html", "notebook2.embed_files", "notebook2.embed-preview.html"];
131+
cleanup.forEach((path) => {
132+
Deno.removeSync(join(dir, path), {recursive: true});
133+
})
134+
return Promise.resolve();
135+
},
136+
});
137+

0 commit comments

Comments
 (0)