From 756146996a2e00f7b7446407b49b01b545110e40 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 7 Sep 2022 10:28:49 -0700 Subject: [PATCH 1/3] don't emit HTML in PDF formats. Closes #2334 --- src/resources/rmd/execute.R | 1 + src/resources/rmd/ojs_static.R | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/resources/rmd/execute.R b/src/resources/rmd/execute.R index 23f99cbf3bc..0c1d4402d24 100644 --- a/src/resources/rmd/execute.R +++ b/src/resources/rmd/execute.R @@ -120,6 +120,7 @@ execute <- function(input, format, tempDir, libDir, dependencies, cwd, params, r # FIXME this test isn't failing in shiny mode, but it doesn't look to be # breaking quarto-shiny-ojs. We should make sure this is right. if (!is_shiny_prerendered(knitr::opts_knit$get("rmarkdown.runtime"))) { + quarto_format <<- format source(file.path(resourceDir, "rmd", "ojs_static.R")) } render_output <- rmarkdown::render( diff --git a/src/resources/rmd/ojs_static.R b/src/resources/rmd/ojs_static.R index 2cfcfdd6030..ba0bfc51430 100644 --- a/src/resources/rmd/ojs_static.R +++ b/src/resources/rmd/ojs_static.R @@ -33,7 +33,10 @@ attach(list( contents, ""); - invisible(knitr:::knit_meta_add(list(structure(class="ojs-define", script_string)))) + # don't emit HTML output in PDF formats. (#2334) + if (knitr:::is_html_output(quarto_format$pandoc$to)) { + invisible(knitr:::knit_meta_add(list(structure(class="ojs-define", script_string)))) + } } ), name = "tools:quarto") From b1bcefe315bd7b5635dd91c72bf1c38ee61f1609 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 7 Sep 2022 10:38:22 -0700 Subject: [PATCH 2/3] use environment --- src/resources/rmd/execute.R | 4 +++- src/resources/rmd/ojs_static.R | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/resources/rmd/execute.R b/src/resources/rmd/execute.R index 0c1d4402d24..758facaf59d 100644 --- a/src/resources/rmd/execute.R +++ b/src/resources/rmd/execute.R @@ -120,7 +120,9 @@ execute <- function(input, format, tempDir, libDir, dependencies, cwd, params, r # FIXME this test isn't failing in shiny mode, but it doesn't look to be # breaking quarto-shiny-ojs. We should make sure this is right. if (!is_shiny_prerendered(knitr::opts_knit$get("rmarkdown.runtime"))) { - quarto_format <<- format + attach(list( + quarto_format = format + ), name = "tools:quarto") source(file.path(resourceDir, "rmd", "ojs_static.R")) } render_output <- rmarkdown::render( diff --git a/src/resources/rmd/ojs_static.R b/src/resources/rmd/ojs_static.R index ba0bfc51430..7262671674a 100644 --- a/src/resources/rmd/ojs_static.R +++ b/src/resources/rmd/ojs_static.R @@ -1,4 +1,3 @@ - attach(list( ojs_define = function(...) { # validate that we aren't in a cached chunk From 77f90fc8021933c3fffe8a896a2a3a0813c7d779 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 7 Sep 2022 10:43:47 -0700 Subject: [PATCH 3/3] changelog --- news/changelog-1.2.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.2.md b/news/changelog-1.2.md index e4a2314bbe2..731004c3a52 100644 --- a/news/changelog-1.2.md +++ b/news/changelog-1.2.md @@ -8,6 +8,7 @@ ## OJS - support `revealjs` and `html` formats in `width` builtin, fallback gracefully otherwise (#2058) +- Don't emit `ojs_define` HTML in non-html formats (#2338) ## Extensions