Skip to content

Commit deea869

Browse files
authored
Merge pull request #12370 from quarto-dev/knitr/output-cell-div
knitr, markdown - Add new lines before creating cell output div
2 parents a2edc85 + a5e28a5 commit deea869

File tree

8 files changed

+138
-1
lines changed

8 files changed

+138
-1
lines changed

src/resources/rmd/hooks.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,12 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
407407
if (identical(options[["results"]], "asis") && !needCell) {
408408
x
409409
} else {
410+
# Newline first and after to ensure Pandoc Fenced Div is correctly parsed
410411
paste0(
412+
"\n",
411413
options[["indent"]], "::: {",
412414
labelId(label), paste(classes, collapse = " ") ,forwardAttr, "}\n", x, "\n", cell.cap ,
413-
options[["indent"]], ":::"
415+
options[["indent"]], ":::\n"
414416
)
415417
}
416418
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
engine: julia
6+
---
7+
8+
This does it:
9+
10+
::: {.cell execution_count=1}
11+
``` {.julia .cell-code}
12+
1 + 1
13+
```
14+
15+
::: {.cell-output .cell-output-display execution_count=1}
16+
```
17+
2
18+
```
19+
:::
20+
:::
21+
22+
23+
Other content
24+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
engine: julia
6+
---
7+
8+
This does it:
9+
```{julia}
10+
1 + 1
11+
```
12+
Other content
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
---
6+
7+
This does it:
8+
9+
::: {.cell execution_count=1}
10+
``` {.python .cell-code}
11+
1 + 1
12+
```
13+
14+
::: {.cell-output .cell-output-display execution_count=1}
15+
```
16+
2
17+
```
18+
:::
19+
:::
20+
21+
22+
Other content
23+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
---
6+
7+
This does it:
8+
```{python}
9+
1 + 1
10+
```
11+
Other content
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
---
6+
7+
This does it:
8+
9+
::: {.cell}
10+
11+
```{.r .cell-code}
12+
1 + 1
13+
```
14+
15+
::: {.cell-output .cell-output-stdout}
16+
17+
```
18+
[1] 2
19+
```
20+
21+
22+
:::
23+
:::
24+
25+
Other content
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Untitled"
3+
format: markdown
4+
keep-md: true
5+
---
6+
7+
This does it:
8+
```{r}
9+
1 + 1
10+
```
11+
Other content
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { dirname, join } from "path";
2+
import { ensureSnapshotMatches, noErrors, printsMessage } from "../../verify.ts";
3+
import { fileLoader } from "../../utils.ts";
4+
import { safeRemoveIfExists } from "../../../src/core/path.ts";
5+
import { testRender } from "../render/render.ts";
6+
7+
// Define engines to test
8+
const engines = [
9+
{ name: "knitr" },
10+
{ name: "jupyter" },
11+
{ name: "julia" }
12+
];
13+
14+
// Run tests for each engine
15+
engines.forEach(engine => {
16+
// Test for engine
17+
const inputQmd = fileLoader(engine.name, "intermediate-markdown-output")("output-cell-div.qmd", "markdown");
18+
const md = join(dirname(inputQmd.input), "output-cell-div.markdown.md");
19+
testRender(inputQmd.input, "markdown", true, [
20+
noErrors,
21+
// Lua Warning are in INFO
22+
printsMessage({ level: "INFO", regex: /WARNING \(.*\)\s+The following string was found in the document: :::/, negate: true}),
23+
ensureSnapshotMatches(md)
24+
], {
25+
teardown: async () => {
26+
safeRemoveIfExists(md);
27+
} });
28+
});
29+

0 commit comments

Comments
 (0)