Skip to content

Commit e5ed82b

Browse files
authored
Fix embed and verbatim knitr's engine for revealjs (#4732)
* Do not override the knitr's `embed` engine with internal quarto's `embed` handler Currently the `embed` handler is only for Jupyter. Discovered while looking at #4712 - revealjs does not work with knitr embed engine * Set echo = TRUE for embed and verbatim engine when revealjs because those engine expect echo, but revealjs default to FALSE * Add embed to ignored engine for chunk hook * Add test for knitr revealjs fix regarding verbatim and embed * Revert "Do not override the knitr's `embed` engine with internal quarto's `embed` handler" This reverts commit 53d8703. * Internal languages are only handlers of type cell Other language are shortcodes * For embed and verbatim engine, always set to TRUE This will avoid format defaulting to echo: false to hide those chunks
1 parent 7e62b54 commit e5ed82b

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/core/handlers/base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,15 @@ function makeHandlerContext(
279279
return { context, results };
280280
}
281281

282+
// return cell language handler only
282283
export function languages(): string[] {
283-
return Object.keys(handlers);
284+
const cellLanguage = [];
285+
for (const [k, v] of Object.entries(handlers)) {
286+
if (v.type === "cell") {
287+
cellLanguage.push(k);
288+
}
289+
}
290+
return cellLanguage;
284291
}
285292

286293
export async function languageSchema(

src/resources/rmd/hooks.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
4444
options[["results"]] <- "hold"
4545
}
4646
}
47+
# for source-only engine, always set `echo: TRUE`
48+
if (options[["engine"]] %in% c("embed", "verbatim")) {
49+
options[["echo"]] <- TRUE
50+
}
51+
4752
options
4853
}
4954

@@ -162,9 +167,8 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
162167
return(x)
163168
}
164169

165-
# verbatim and comment should do nothing
166-
if (identical(options[["engine"]], "verbatim") ||
167-
identical(options[["engine"]], "comment")) {
170+
# verbatim-like and comment knitr's engine should do nothing
171+
if (options[["engine"]] %in% c("verbatim", "embed", "comment")) {
168172
return(x)
169173
}
170174

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cat("this is code.R\n")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
format:
3+
revealjs: default
4+
engine: knitr
5+
_quarto:
6+
tests:
7+
revealjs:
8+
ensureHtmlElements:
9+
- ["#verbatim div.sourceCode pre code", "#embed div.sourceCode pre code"]
10+
- ["#verbatim div.cell", "#embed div.cell"]
11+
ensureFileRegexMatches:
12+
- ["this is code\\.R"]
13+
- []
14+
---
15+
16+
From issue : https://github.com/quarto-dev/quarto-cli/issues/4712
17+
18+
## Verbatim {#verbatim}
19+
20+
````{verbatim}
21+
Some content
22+
````
23+
24+
## Embed {#embed}
25+
26+
````{embed, file = "code.R"}
27+
````
28+

0 commit comments

Comments
 (0)