From d9b508ccf329ef10577c532a926a5b85ea71aeb0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 7 Nov 2025 18:02:55 +0100 Subject: [PATCH] Fix R code cells with empty lang option producing invalid class attributes When R code cells use `lang: ""`, the empty string was being converted to an invalid class attribute `{. .cell-code}` (space after period with no language). This appeared as literal text in output instead of being parsed as a valid code block attribute. Root cause: `block_attr()` function in hooks.R was adding dot prefix to empty strings. Now checks both NULL and empty string before adding prefix. Fixes #13656 --- news/changelog-1.9.md | 1 + src/resources/rmd/hooks.R | 4 +++- tests/docs/smoke-all/2025/11/07/13656.qmd | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/2025/11/07/13656.qmd diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md index 36e401833d..a1085ae47d 100644 --- a/news/changelog-1.9.md +++ b/news/changelog-1.9.md @@ -61,3 +61,4 @@ All changes included in 1.9: - ([#13402](https://github.com/quarto-dev/quarto-cli/issues/13402)): `nfpm` () is now used to create the `.deb` package, and new `.rpm` package. Both Linux packages are also now built for `x86_64` (`amd64`) and `aarch64` (`arm64`) architectures. - ([#13528](https://github.com/quarto-dev/quarto-cli/pull/13528)): Adds support for table specification using nested lists and the `list-table` class. - ([#13575](https://github.com/quarto-dev/quarto-cli/pull/13575)): Improve CPU architecture detection/reporting in macOS to allow quarto to run in virtualized environments such as OpenAI's `codex`. +- ([#13656](https://github.com/quarto-dev/quarto-cli/issues/13656)): Fix R code cells with empty `lang: ""` option producing invalid markdown class attributes. diff --git a/src/resources/rmd/hooks.R b/src/resources/rmd/hooks.R index 7364f36749..7e3ca19dbd 100644 --- a/src/resources/rmd/hooks.R +++ b/src/resources/rmd/hooks.R @@ -1120,8 +1120,10 @@ is_label_type <- function(type, label) { block_attr <- function(id = NULL, lang = NULL, class = NULL, attr = NULL) { id <- labelId(id) - if (!is.null(lang)) { + if (!is.null(lang) && nzchar(lang)) { lang <- paste0(".", lang) + } else { + lang <- NULL } if (!is.null(class)) { class <- paste(block_class(class)) diff --git a/tests/docs/smoke-all/2025/11/07/13656.qmd b/tests/docs/smoke-all/2025/11/07/13656.qmd new file mode 100644 index 0000000000..c3ead7d723 --- /dev/null +++ b/tests/docs/smoke-all/2025/11/07/13656.qmd @@ -0,0 +1,20 @@ +--- +title: "Empty lang option should not produce invalid class (#13656)" +format: html +keep-md: true +_quarto: + tests: + html: + ensureFileRegexMatches: + - [] + - ['\{\. \.cell-code\}'] # Should NOT have invalid literal class in HTML +--- + +## Test Case + +R code cell with empty lang option should not produce invalid class: + +```{r} +#| lang: "" +23 +```