我可以在rmarkDown html_document中删除[代码]按钮,同时仍使用[显示/隐藏所有代码]按钮显示代码

发布于 2025-02-13 04:54:02 字数 1105 浏览 0 评论 0原文

虽然我喜欢显示/隐藏code_folding html_document在rmarkDown中输出的属性允许的所有代码,但我不喜欢看到a <<<代码>代码到处都有一些代码,因为它在文档中创建了“空行”。

有没有一种方法可以使用属性或一些JavaScript魔术删除此/这些 button(s),

  • 无需更改RMD文档(即。
  • 而 通过显示/隐藏所有代码,显示/隐藏所有代码切换

以下是一个示例:

---                     
title: "Test"           
date: '`r Sys.Date()`'  
output:                 
 html_document:         
    code_download: true 
    code_folding: 'hide'
---                     
                        
# Title 1               
                        
chunk 1                 
                        
```{r, eval = FALSE}    
1+1                     
```                     
                        
```{r, eval = FALSE}    
1+2                     
```                     
                        
```{r}                  
1+3                     
```  

               

呈现这样的渲染:

While I like the possibility to show/hide all code that is allowed by the code_folding property of the html_document output in rmarkdown, I do not like that I have to see a Code button everywhere there is some code because it creates "empty line(s)" in the document.

Is there a way to remove this/these Code button(s) with a property or some javascript magic

  • without altering the Rmd document (ie. not writing some additional code in the document itself)
  • while still allowing to show/hide all code through the Show/Hide All Code toggle

Here is an example:

---                     
title: "Test"           
date: '`r Sys.Date()`'  
output:                 
 html_document:         
    code_download: true 
    code_folding: 'hide'
---                     
                        
# Title 1               
                        
chunk 1                 
                        
```{r, eval = FALSE}    
1+1                     
```                     
                        
```{r, eval = FALSE}    
1+2                     
```                     
                        
```{r}                  
1+3                     
```  

               

Which renders like this:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

银河中√捞星星 2025-02-20 04:54:02

您可以使用CSS规则隐藏代码折叠按钮。

---                     
title: "Test"           
date: '`r Sys.Date()`'  
output:                 
  html_document: 
    css: "style.css"        
    code_download: true 
    code_folding: 'hide'
---

style.css

.code-folding-btn {
  display: none;
}

You can hide the code-folding buttons with a css rule.

---                     
title: "Test"           
date: '`r Sys.Date()`'  
output:                 
  html_document: 
    css: "style.css"        
    code_download: true 
    code_folding: 'hide'
---

The style.css

.code-folding-btn {
  display: none;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文