diff --git a/news/changelog-1.8.md b/news/changelog-1.8.md index f563f1261d2..1d73bd6c744 100644 --- a/news/changelog-1.8.md +++ b/news/changelog-1.8.md @@ -137,6 +137,7 @@ All changes included in 1.8: - ([#13085](https://github.com/quarto-dev/quarto-cli/pull/13085)): Avoid `kbd` shortcode crashes on unknown OS keys. - ([#13164](https://github.com/quarto-dev/quarto-cli/pull/13164)): add `julia` to execute schema to allow autocomplete suggestions. (@mcanouil) - ([#13121](https://github.com/quarto-dev/quarto-cli/issues/13121)): Allow `contents` shortcode to find inline elements. +- ([#13216](https://github.com/quarto-dev/quarto-cli/issues/13216)): Properly disable `downlit` (`code-link`) and enable `code-annotations` when non-R code blocks are present. ## Quarto Internals diff --git a/src/resources/rmd/rmd.R b/src/resources/rmd/rmd.R index 751a90f0e43..9335d870bf3 100755 --- a/src/resources/rmd/rmd.R +++ b/src/resources/rmd/rmd.R @@ -34,8 +34,11 @@ knit_meta <- lapply(data, jsonlite::unserializeJSON) # determine files_dir - files_dir <- if (!is.null(libDir)) libDir else + files_dir <- if (!is.null(libDir)) { + libDir + } else { rmarkdown:::knitr_files_dir(output) + } # yield pandoc format list( @@ -60,7 +63,9 @@ # bail if we don't have any perserved chunks and aren't doing code linking code_link <- isHTML && isTRUE(format$render$`code-link`) - if (length(preserved_chunks) == 0 && code_link == FALSE) return() + if (length(preserved_chunks) == 0 && code_link == FALSE) { + return() + } # change to input dir and make input relative oldwd <- setwd(dirname(rmarkdown:::abs_path(input))) @@ -97,7 +102,14 @@ # within a code chunk for (x in seq_along(chunkStarts)) { start <- chunkStarts[x] - end <- chunkEnds[x] + # Ensure end is greater than start + end <- start + for (e in chunkEnds) { + if (e > start) { + end <- e + break + } + } for (y in start:end) { if (y > start && y < end) { chunkMap[y] <- TRUE @@ -107,7 +119,7 @@ # look for at least one annotations that is in a code chunk for (a in annotations) { - if (chunkMap[a] == TRUE) { + if (chunkMap[a]) { hasAnnotations <- TRUE break } @@ -191,8 +203,12 @@ run <- function(input, port, host) { shiny_args <- list() - if (!is.null(port)) shiny_args$port <- port - if (!is.null(host)) shiny_args$host <- host + if (!is.null(port)) { + shiny_args$port <- port + } + if (!is.null(host)) { + shiny_args$host <- host + } # we already ran quarto render before the call to run Sys.setenv(RMARKDOWN_RUN_PRERENDER = "0") @@ -226,7 +242,9 @@ # print execute-debug message ("spin" and "run" don't pass format option) debug <- (!request$action %in% c("spin", "run")) && isTRUE(params$format$execute[["debug"]]) - if (debug) message("[knitr engine]: ", request$action) + if (debug) { + message("[knitr engine]: ", request$action) + } # dispatch request if (request$action == "spin") { @@ -267,7 +285,9 @@ } # write results - if (debug) message("[knitr engine]: writing results") + if (debug) { + message("[knitr engine]: writing results") + } resultJson <- jsonlite::toJSON(auto_unbox = TRUE, result) xfun:::write_utf8(paste(resultJson, collapse = "\n"), request[["results"]]) if (debug) message("[knitr engine]: exiting") diff --git a/tests/docs/smoke-all/2025/08/14/issue13216.qmd b/tests/docs/smoke-all/2025/08/14/issue13216.qmd new file mode 100644 index 00000000000..46de8f5623d --- /dev/null +++ b/tests/docs/smoke-all/2025/08/14/issue13216.qmd @@ -0,0 +1,24 @@ +--- +title: "Issue 13216" +format: html +code-annotations: below +code-link: true +_quarto: + tests: + html: + ensureHtmlElements: + - + - "dl.code-annotation-container-grid" +--- + +`downlit` (`code-link`) should be disable and `code-annotations` should be enabled. + +``` +hello +``` + +```{r} +2 + 2 # <1> +``` + +1. This should be styled as a popup.