Skip to content

Commit d5203c6

Browse files
authored
Merge pull request #1257 from quarto-dev/reveal-output-location-slide
[reveal] fix `output-location: slide`
2 parents ac8389d + ef4ebf2 commit d5203c6

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

src/format/reveal/format-reveal.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ function revealHtmlPostprocessor(
343343
const parentSlide = findParentSlide(slideOutputEl);
344344
if (parentSlide && parentSlide.parentElement) {
345345
const newSlide = doc.createElement("section");
346-
newSlide.id = parentSlide?.id ? parentSlide.id + "-output" : "";
346+
newSlide.setAttribute(
347+
"id",
348+
parentSlide?.id ? parentSlide.id + "-output" : "",
349+
);
347350
for (const clz of parentSlide.classList) {
348351
newSlide.classList.add(clz);
349352
}
@@ -361,7 +364,9 @@ function revealHtmlPostprocessor(
361364
newSlide.appendChild(headingEl);
362365
}
363366
newSlide.appendChild(slideOutputEl);
364-
parentSlide.parentElement.appendChild(newSlide);
367+
// Place the new slide after the current one
368+
const nextSlide = parentSlide.nextElementSibling;
369+
parentSlide.parentElement.insertBefore(newSlide, nextSlide);
365370
}
366371
}
367372

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "output-location"
3+
format: revealjs
4+
---
5+
6+
## Slide before {#first-slide}
7+
8+
Words
9+
10+
## The slide with the code {#loc-slide}
11+
12+
```{r}
13+
#| echo: true
14+
#| output-location: slide
15+
plot(mtcars)
16+
```
17+
18+
## Next slides {#next-slide}
19+
20+
Words
21+
22+
## The slide with the code {#loc-column}
23+
24+
```{r}
25+
#| echo: true
26+
#| output-location: column
27+
plot(mtcars)
28+
```
29+
30+
## The slide with the code {#loc-fragment}
31+
32+
```{r}
33+
#| echo: true
34+
#| output-location: fragment
35+
plot(mtcars)
36+
```
37+
38+
## The slide with the code {#loc-col-fragment}
39+
40+
```{r}
41+
#| echo: true
42+
#| output-location: column-fragment
43+
plot(mtcars)
44+
```

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
*/
77

88
import { docs, fileLoader, outputForInput } from "../../utils.ts";
9-
import { ensureHtmlElements } from "../../verify.ts";
9+
import {
10+
ensureHtmlElements,
11+
ensureHtmlSelectorSatisfies,
12+
} from "../../verify.ts";
1013
import { testRender } from "./render.ts";
1114

1215
// demo file renders ok
@@ -78,3 +81,29 @@ testRender(fragmentsDiv.input, "revealjs", false, [
7881
"#slide-2 > div.fragment > h3",
7982
], []),
8083
]);
84+
85+
// output-location
86+
const outputLocation = fileLoader("reveal")("output-location.qmd", "revealjs");
87+
testRender(outputLocation.input, "revealjs", false, [
88+
ensureHtmlElements(outputLocation.output.outputPath, [
89+
"section#loc-slide + section#loc-slide-output > div.output-location-slide",
90+
"section#loc-fragment > div.fragment > div.cell-output-display",
91+
"section#loc-col-fragment > div.columns > div.column:nth-child(2).fragment > div.cell-output-display",
92+
], [
93+
"section#loc-slide > div.output-location-slide",
94+
]),
95+
ensureHtmlSelectorSatisfies(
96+
outputLocation.output.outputPath,
97+
"section#loc-column > div.columns > div.column",
98+
(nodeList) => {
99+
return nodeList.length === 2;
100+
},
101+
),
102+
ensureHtmlSelectorSatisfies(
103+
outputLocation.output.outputPath,
104+
"section#loc-col-fragment > div.columns > div.column",
105+
(nodeList) => {
106+
return nodeList.length === 2;
107+
},
108+
),
109+
]);

0 commit comments

Comments
 (0)