quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.99k stars 328 forks source link

code-line-numbers and fragments not working as expected/hoped in revealjs #11585

Open rpruim opened 2 days ago

rpruim commented 2 days ago

Bug description

I would like to use `#| code-line-numbers and custom fragments to annotate revealjs slides, but I haven't been able to get it to work. Is this possible?

Here is the kind of thing I have in mind.

---
title: "code-line-numbers"
sbustitle: "and fragments"
format: revealjs
execute: 
  echo: true
---

## A slide

```{r}
#| code-line-numbers: "|1|2"
x <- 1
y <- 2

:::{.fragment fragment-index=1} Comment on first line of code :::

:::{.fragment fragment-index=2} Comment on second line of code :::



But when I view, the code highlighting is not synced up with the fragment indexing.

### Steps to reproduce

_No response_

### Expected behavior

_No response_

### Actual behavior

_No response_

### Your environment

R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin23.4.0
Running under: macOS Sonoma 14.4
RStudio: 2024.09.1+394 (2024.09.1+394)

### Quarto check output

Quarto 1.5.56
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.56
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /opt/homebrew/bin
      Version: undefined

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.4
      Path: /Users/rpruim/.virtualenvs/r-reticulate/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /opt/homebrew/Cellar/r/4.4.1/lib/R
      LibPaths:
        - /opt/homebrew/lib/R/4.4/site-library
        - /opt/homebrew/Cellar/r/4.4.1/lib/R/library
      knitr: 1.49
      rmarkdown: 2.29

[✓] Checking Knitr engine render......OK
mcanouil commented 1 day ago

code-line-numbers does not allow you to set fragment index, it creates an index for each line you set, so it is not expected for the code to have anything but a sequence of four elements in your case. For instance, since you set manually index 1 and 2, it means first line will be index 3 and the second line will be index 4.

So, this would be a feature request to allow to manually set fragment index in addition to setting the lines.

Manual workaround + code annotation

````qmd --- title: "code-line-numbers" format: revealjs code-annotations: below execute: echo: true --- ## A slide ```{r} #| code-line-numbers: "1" x <- 1 # <1> ``` 1. Comment on first line of code ## A slide ```{r} #| code-line-numbers: "2" x <- 1 # <1> y <- 2 # <2> ``` 1. [Comment on first line of code]{style="opacity: 0.25;"} 2. Comment on second line of code ````