Pandoc allows to add number lined in code chunk by adding the class .number-lines to code chunk. This can be done in R Markdown using class.source knitr option, but is also possible in Quarto with code-line-numbers = true options. In Quarto this is also the default for revealjs format.
Trying to activate downlit for those (using highlight_downlit: true in Rmd or code-link: true in Quarto) will not apply the highlighting or the code linking.
Quarto example
````markdown
---
title: demo line number
format:
html: default
code-link: true
---
# Line numbered
```{r}
#| code-line-numbers: true
library(glue)
glue("this is {i}", i = "me")
```
# Not line numbered
```{r}
library(glue)
glue("this is {i}", i = "me")
```
````
Rmd example
````markdown
---
title: Rmd test
output:
html_document:
highlight_downlit: true
---
# Line numbered
```{r, class.source = ".number-lines"}
library(glue)
glue("this is {i}", i = "me")
```
# Not line numbered
```{r}
library(glue)
glue("this is {i}", i = "me")
```
````
Both are using downlit::downlit_html_path() on the result of Pandoc conversion.
downlit is replacing all the the <pre> and it would require here to preserve the span at each line.
Opening this issue to document this limitation and to discuss how to handle that. Happy to help on this as this is needed for Quarto code-link to work in presentation where line numbers is the default currently.
Pandoc allows to add number lined in code chunk by adding the class
.number-lines
to code chunk. This can be done in R Markdown usingclass.source
knitr option, but is also possible in Quarto withcode-line-numbers = true
options. In Quarto this is also the default for revealjs format.Trying to activate downlit for those (using
highlight_downlit: true
in Rmd orcode-link: true
in Quarto) will not apply the highlighting or the code linking.Quarto example
````markdown --- title: demo line number format: html: default code-link: true --- # Line numbered ```{r} #| code-line-numbers: true library(glue) glue("this is {i}", i = "me") ``` # Not line numbered ```{r} library(glue) glue("this is {i}", i = "me") ``` ````Rmd example
````markdown --- title: Rmd test output: html_document: highlight_downlit: true --- # Line numbered ```{r, class.source = ".number-lines"} library(glue) glue("this is {i}", i = "me") ``` # Not line numbered ```{r} library(glue) glue("this is {i}", i = "me") ``` ````Both are using
downlit::downlit_html_path()
on the result of Pandoc conversion.This is due to two things mainly
<pre>
will have more classes like<pre class="sourceCode numberSource r number-lines">
and detection does not account for that https://github.com/r-lib/downlit/blob/8ee71d8cba7e77e05cbf01de8f1ecff1536b3741/R/downlit-html.R#L47-L48Number per line is done by Pandoc highlighting through the addition of spans like
<span id="cb1-1"><a href="#cb1-1"></a>
HTML from example above:downlit is replacing all the the
<pre>
and it would require here to preserve the span at each line.Opening this issue to document this limitation and to discuss how to handle that. Happy to help on this as this is needed for Quarto
code-link
to work in presentation where line numbers is the default currently.