Skip to content

fix: code-annotation not detected when non-R code blocks are present #13218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ All changes included in 1.8:
- ([#12782](https://github.com/quarto-dev/quarto-cli/pull/12782)): fix bug on `safeRemoveDirSync`'s detection of safe directory boundaries.
- ([#12853](https://github.com/quarto-dev/quarto-cli/issues/12853)): fix replaceAll() escaping issue with embedded notebooks containing `$` in their Markdown.
- ([#12939](https://github.com/quarto-dev/quarto-cli/pull/12939)): Upgrade `mermaidjs` to 11.6.0.
- ([#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.
36 changes: 28 additions & 8 deletions src/resources/rmd/rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)))
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions tests/docs/smoke-all/2025/08/14/issue13216.qmd
Original file line number Diff line number Diff line change
@@ -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.
Loading