I am writing a manual for some work stuff in Quarto. Some of the pages will include both R and Python. I am wondering if there is a way to automatically label each code chunk with the language in that code chunk. I am currently trying it manually via title and #| label: R but neither are outputting anything.
A nice suggestion. We're seeing a lot of requests for customising Quarto templates at work at the moment.
We can achieve something like this with CSS since you are doing HTML output. But as a warning, this method would not be considered friendly to those with accessibility needs because adding text through CSS means a screen reader will not see it.
---
title: "quarto_lang_label"
format:
html:
css: language_code.css
---
## Basic code chunks
In python:
```{python}
1 + 1
```
In R:
```{r}
1 + 1
```
Some more R:
```{r}
f1 = function(x) {
return(x * x + x)
}
```
You'll have to add classes to have the label for other languages:
```{js}
foo = document.getElementById("foo");
```