DaveRGP
DaveRGP

Reputation: 1480

Does knitr not support syntax highlighting in SQL common table expressions?

knitr is documented as supporting syntax highlighting in SQL, however, in the following example only one chunk is highlighted correctly:

---
title: "R Notebook"
output:
  html_document: default
---

```{sql select, eval=FALSE}
SELECT foo
FROM bar
WHERE jimminy > zoinks
```


```{sql with, eval=FALSE}
WITH (
SELECT bar
FROM foo
)
SELECT foo
FROM bar
WHERE jimminy > zoinks
```

After some testing I am attributing this to the common table expression (the WITH statement).

Is there something simple available to 'turn on' syntax highlighting for both chunks? Anything short of re-structuring the queries to not be CTE?

Upvotes: 2

Views: 535

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30164

This is because the rmarkdown is still using a fairly old version of highlight.js (similar to rstudio/rmarkdown#907). You can choose not to use highlight.js by specifying other values for the highlight option, e.g.

---
title: "R Notebook"
output:
  html_document: 
    highlight: tango
---

```{sql select, eval=FALSE}
SELECT foo
FROM bar
WHERE jimminy > zoinks
```


```{sql with, eval=FALSE}
WITH (
SELECT bar
FROM foo
)
SELECT foo
FROM bar
WHERE jimminy > zoinks
```

Upvotes: 4

Related Questions