rstudio / distill

Distill for R Markdown
https://rstudio.github.io/distill/
Apache License 2.0
422 stars 57 forks source link

Line numbers for code blocks #473

Closed SES-CE closed 2 years ago

SES-CE commented 2 years ago

Hi,

Is it possible to have line numbers in my code blocks using distill?

I'd like to have line numbers for code blocks so I can reference the code in my article made using distill but I have been unable to get them shown in the output successfully.

Searching the web I found an answer for a general output with 'html_output' as in this post.

Using the code from the post it does not directly transfer to a 'distill::distill_article:' output.

---
title: "Untitled"
author: "Unauthored"
date: "1/1/2020"
output:
    distill::distill_article:
    highlight: tango

---

```{css, echo = FALSE}
.sourceCode { overflow: visible; }
knitr::opts_chunk$set(echo = TRUE)

Line numbers

if (TRUE) {
  x <- 1:10
  x + 1
}
cderv commented 2 years ago

This is an issue with downlit https://github.com/r-lib/downlit/issues/133 which is used by distill to highlight code block by default https://rstudio.github.io/distill/basics.html#syntax-highlighting

Theoretically, it should be possible to make that works by deactivating downlit

---
title: "Untitled"
author: "Unauthored"
date: "1/1/2020"
output:
    distill::distill_article:
      highlight: tango
      highlight_downlit: false
---

```{css, echo = FALSE}
.sourceCode { overflow: visible; }
knitr::opts_chunk$set(echo = TRUE)

Line numbers

if (TRUE) {
  x <- 1:10
  x + 1
}


However, it seems there is some CSS issues. 
![image](https://user-images.githubusercontent.com/6791940/189959661-933210c9-2c24-415d-928f-bd8bfed357e4.png)

This should be fixed in **distill** and the former in **downlit**

Thank you for the report ! 
cderv commented 2 years ago

The styling should be fixed when highlight_downlit = FALSE and line numbering activated.

Thanks for the report

SES-CE commented 2 years ago

Thanks a lot!