Xaringan: Highlight multi-line strings in a code chunk

I am making xaringan slides. I have a string that is split up over multiple lines in a code chunk. Is it possible to have the entire string highlighted?

Below is a picture of what I mean. I would like the entire string, which represents a SQL query, formatted in red.

This appears to work in RMarkdown (not xaringan). Thought I should ask here first before opening a GH issue.

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

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.