r-lib / hugodown

Make websites with hugo and RMarkdown
https://hugodown.r-lib.org
Other
166 stars 24 forks source link

R code bocks are always collapsed #100

Closed leonardopsantos closed 3 years ago

leonardopsantos commented 3 years ago

Hi there! I'm having a bit of trouble making hugodown produce code blocks that aren't collapsed (R code a different block as the eval result). Say that I have the following R code block:

```{r, collapse=FALSE}
# loading and checking the data
print("mensagem")
```

This will generate the following MD:

<div class="highlight">

<pre class='chroma'><code class='language-r' data-lang='r'><span class='c'># loading and checking the data</span>
<span class='nf'><a href='https://rdrr.io/r/base/print.html'>print</a></span><span class='o'>(</span><span class='s'>"mensagem"</span><span class='o'>)</span>
<span class='c'>#&gt; [1] "mensagem"</span></code></pre>

</div>

What I would like is to have them in separate divs. I'm able to achieve that by having two separate code blocks:

```{r, eval=FALSE}
# loading and checking the data
print("mensagem")
```
```{r, echo=FALSE, eval=TRUE}
# loading and checking the data
print("mensagem")
```

Which will yield me

<div class="highlight">

<pre class='chroma'><code class='language-r' data-lang='r'><span class='c'># loading and checking the data</span>
<span class='nf'><a href='https://rdrr.io/r/base/print.html'>print</a></span><span class='o'>(</span><span class='s'>"mensagem"</span><span class='o'>)</span></code></pre>

</div>

<div class="highlight">

<pre class='chroma'><code class='language-r' data-lang='r'><span class='c'>#&gt; [1] "mensagem"</span></code></pre>

</div>

How can I achieve the same result without having to use two separate code blocks?

Thanks!!

hadley commented 3 years ago

Unfortunately hugodown currently only supports collapsed code blocks. This is unlikely to change in the near future.

leonardopsantos commented 3 years ago

That's a hard-coded option that could be fixed:

if (tidyverse_style) {
    knitr$opts_chunk$collapse <- TRUE
    knitr$opts_chunk$comment <- "#>"
    knitr$opts_chunk$fig.align <- "center"
    knitr$opts_chunk$out.width <- "700px"
  }

If I know enough R, I'd fix it myself.

hadley commented 3 years ago

Collapsed code blocks are a strong assumption that's woven through the syntax highlighting and css. It's not a simple change.

leonardopsantos commented 3 years ago

Ah, understood! Many thanks for the clarification.