Skip to content

downlit does not keep code source option set with knitr #149

@cderv

Description

@cderv

knitr supports class.source and attr.source to add class and attributes on fenced code blocks

Take this example

---
output: 
  rmarkdown::html_document:
    highlight: pygments
---

```{r select1, class.source = "my-class"}
print("Hello there")
```

This is the markdown produced by knitr

```{.r .my-class}
print("Hello there")
```

and my-class will be added by Pandoc to <pre> in code block

<div class="sourceCode" id="cb1">
<pre class="sourceCode r my-class"><code class="sourceCode r">
<span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(<span class="st">&quot;Hello there&quot;</span>)</span>
</code></pre></div>

downlit is not saving the addition classes to put them back in the new <pre> that it creates.

Related to #133 which is slightly related as order of classes on pre messes up downlit_html_path().

A fix should take into account both issues probably

Initially reported in r-lib/pkgdown#2147 by r-lib/pkgdown#2147

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions