How can a class attribute be passed from a chunk to html in a bs4_book in R?

Viewed 24

I am writing a bs4_book in RStudio with the package bookdown.

I have some long codes, and I want them to appear in the book, but only with a maximal size, and let the reader scroll them down if he wants to read them.

I have seen that bootstrap enables the use of the class .pre-scrollable to obtain such a result (see here).

When I define knitr::opts_chunk$set(class.source = "pre-scrollable"), I obtain in the rendered .md file the code ```{.r .pre-scrollable} to begin each code chunk, which I though would be fine.

However, when converted to html, the class pre-scrollable is no longer present. The html code begins like that: <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">.

If I append to it <pre class="pre-scrollable">, the html file render the code chunk as expected. However, without it, it does not work.

What should I change in my code in order to make it work?

Here a try to do a reprex:

--- 
title: "Documentation of the tools for the surveillance programme for AI and ND"
author: "Author"
date: "`r format(Sys.time(), '%B %d, %Y')`"
documentclass: book
---

# Introduction

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
                      class.source = "pre-scrollable")
```

Some text

```{r mtcars, include=FALSE}
#This is a very, very long code chunk

#There is some other lines

#It should really be very long

#Let's add some other comments

#It's still not finished

#I repeat myself, but it should be long

#It seems we are still filling the chunk with useless comments

#We should almost have enough lines

#Maybe one more

#And now we can put some real code

knitr::kable(mtcars)
```

Here some other random text

```{r, eval=FALSE}
bookdown::render_book()
```

I am not really sure how to make a reprex with bs4_book, I hope this is sufficient.

Thanks in advance for your help.

0 Answers
Related