From bf4234354928ad5d3287da1293e0519caa2e5731 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 28 Mar 2023 21:15:10 -0700 Subject: [PATCH 1/2] only attach ojs_define etc if needed. --- src/resources/rmd/execute.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/resources/rmd/execute.R b/src/resources/rmd/execute.R index c0f5ad33a88..6f87e05b3ef 100644 --- a/src/resources/rmd/execute.R +++ b/src/resources/rmd/execute.R @@ -117,9 +117,14 @@ execute <- function(input, format, tempDir, libDir, dependencies, cwd, params, r df_print = df_print ) + # we need ojs only if markdown has ojs code cells + # inspect code cells for spaces after line breaks + + needs_ojs <- grepl("\n[[:space:]]*```+\\{ojs\\}", markdown) # 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"))) { + if (!is_shiny_prerendered(knitr::opts_knit$get("rmarkdown.runtime")) && + needs_ojs) { attach(list( quarto_format = format ), name = "tools:quarto") From 0d0c35f4da27f4f7eca46b9e30f600bd2bcd5127 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 29 Mar 2023 09:34:44 -0700 Subject: [PATCH 2/2] more robust regex --- src/resources/rmd/execute.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/rmd/execute.R b/src/resources/rmd/execute.R index 6f87e05b3ef..0a0fee3b951 100644 --- a/src/resources/rmd/execute.R +++ b/src/resources/rmd/execute.R @@ -120,7 +120,7 @@ execute <- function(input, format, tempDir, libDir, dependencies, cwd, params, r # we need ojs only if markdown has ojs code cells # inspect code cells for spaces after line breaks - needs_ojs <- grepl("\n[[:space:]]*```+\\{ojs\\}", markdown) + needs_ojs <- grepl("^[[:space:]]*```+\\{ojs[^}]*\\}", markdown) # 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")) &&