Here is a reproducible example: (it really helps to get one)
---
title: "test"
output: xaringan::moon_reader
---
# test
```{r, eval = FALSE}
df <- dbGetQuery(con, "SELECT film_id, title, description FROM
film WHERE release_year = 2006")
head(df, 3)
```
I believe this is an issue with Remark.js library that xaringan is using. The new line makes the code parsing with highlight.js not working as expected.
Not having a new line is making the string highlight correct
---
title: "A Minimal Book Example"
output: xaringan::moon_reader
---
# test
```{r, eval = FALSE}
df <- dbGetQuery(
con,
"SELECT film_id, title, description FROM film WHERE release_year = 2006"
)
head(df, 3)
```
Issue will be with any multiline string:
---
title: "A Minimal Book Example"
output: xaringan::moon_reader
---
# test
```{r, eval = FALSE}
query <- "Long string
multi line"
```
So this would need to be filled upstream probably. Tracked here: Multi line string highlighting is not correct · Issue #356 · yihui/xaringan · GitHub