Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cderv opened this issue Mar 18, 2022 · 2 comments
Open

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

cderv opened this issue Mar 18, 2022 · 2 comments
Labels
feature a feature request or enhancement

Comments

@cderv
Copy link
Contributor

cderv commented Mar 18, 2022

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
---
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
---
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

    downlit/R/downlit-html.R

    Lines 47 to 48 in 8ee71d8

    # Usual block generated by pandoc (after syntax highlighting)
    ".//pre[contains(@class, 'sourceCode r')]",

  • Number 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:

<div class="sourceCode" id="cb1">
    <pre class="sourceCode numberSource r number-lines">
        <code class="sourceCode r">
            <span id="cb1-1"><a href="#cb1-1"></a><span class="fu">library</span>(glue)</span>
            <span id="cb1-2"><a href="#cb1-2"></a><span class="fu">glue</span>(<span class="st">"this is {i}"</span>, <span class="at">i =</span> <span class="st">"me"</span>)</span>
        </code>
    </pre>
</div>

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.

@hadley
Copy link
Member

hadley commented Mar 19, 2022

Also related to #13

@cderv
Copy link
Contributor Author

cderv commented Jun 17, 2022

Related to #139 in the sense that Pandoc a span per line in the input, and downlit does not keep this line wrapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants