r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

`downlit_html_*` should support Pandoc's document with numbered line #133

Open cderv opened 2 years ago

cderv commented 2 years ago

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.

This is due to two things mainly

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.

hadley commented 2 years ago

Also related to #13

cderv commented 2 years ago

Related to https://github.com/r-lib/downlit/issues/139 in the sense that Pandoc a span per line in the input, and downlit does not keep this line wrapping.