Skip to content

Commit d9b508c

Browse files
committed
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
1 parent 25bdae6 commit d9b508c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ All changes included in 1.9:
6161
- ([#13402](https://github.com/quarto-dev/quarto-cli/issues/13402)): `nfpm` (<https://nfpm.goreleaser.com/>) 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.
6262
- ([#13528](https://github.com/quarto-dev/quarto-cli/pull/13528)): Adds support for table specification using nested lists and the `list-table` class.
6363
- ([#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`.
64+
- ([#13656](https://github.com/quarto-dev/quarto-cli/issues/13656)): Fix R code cells with empty `lang: ""` option producing invalid markdown class attributes.

src/resources/rmd/hooks.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,10 @@ is_label_type <- function(type, label) {
11201120

11211121
block_attr <- function(id = NULL, lang = NULL, class = NULL, attr = NULL) {
11221122
id <- labelId(id)
1123-
if (!is.null(lang)) {
1123+
if (!is.null(lang) && nzchar(lang)) {
11241124
lang <- paste0(".", lang)
1125+
} else {
1126+
lang <- NULL
11251127
}
11261128
if (!is.null(class)) {
11271129
class <- paste(block_class(class))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Empty lang option should not produce invalid class (#13656)"
3+
format: html
4+
keep-md: true
5+
_quarto:
6+
tests:
7+
html:
8+
ensureFileRegexMatches:
9+
- []
10+
- ['\{\. \.cell-code\}'] # Should NOT have invalid literal class in HTML
11+
---
12+
13+
## Test Case
14+
15+
R code cell with empty lang option should not produce invalid class:
16+
17+
```{r}
18+
#| lang: ""
19+
23
20+
```

0 commit comments

Comments
 (0)