R Markdown和Blogdown-使用eval = F突出显示语法

时间:2018-11-11 00:24:23

标签: r r-markdown blogdown

我正在使用Blogdown / Hugo建立一个网站。我要“手动”组装代码和输出,而不是用编织器动态编织,因为我不想上传数据集。

因此,我正在使用CSS样式在代码等周围放置边框。

这一切都按我的意愿进行。但是,是否有办法在呈现的.html页面中也显示语法突出显示?例如,如果我使用下面的代码运行此代码,则html输出是第一个屏幕抓图enter image description here

,我希望代码的颜色与第二个屏幕截图中的一样。enter image description here

<style>
div.code pre { 
                font-family: 'Source Code Pro', 'Courier New', monospace;
                font-size: 12px;
                background-color:#F5F8FA;
                padding-top: 10px;
                padding-bottom: 10px;
                padding-left: 10px;
                border: 1px solid lightgrey;
                border-radius: 5px;
}
</style>

<style>
div.output pre { 
                font-family: 'Source Code Pro', 'Courier New', monospace;
                font-size: 12px;
                padding-top: 10px;
                padding-bottom: 10px;
                padding-left: 10px;
                border: 1px solid lightgrey;
                border-radius: 5px;
}
</style>


```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = T)
```

```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
```


### Descriptives

The basic frequency histogram for Left and Right eye data, constructed with ggplot2.

<div class = "code">
```{r hist, eval=F}
hist_va <-ggplot(data, aes(x = bcva, fill = bcva < -0.1)) +
  geom_histogram(color = "black",  binwidth = 0.05, center = 0.025) +
  scale_x_continuous(limits = c(-0.4, 0.4), breaks = seq(-0.4, 0.4, 0.1)) +
  theme(legend.position = "none") +
  xlab("Best Corrected Visual Acuity (logMAR)") +
  ylab("Frequency ") +
  scale_fill_manual(values = c("white", "red")) +
  facet_grid(. ~ eye)
```
</div>


Then overlaying the classification thresholds for SuperHuman vision.

<div class = "output">
```{r hist2, eval=F}
##  hist_va + 
##  geom_vline(data = data, aes(xintercept = -0.097, color = "red"), linetype = "dashed") +
##  geom_text(aes(-0.25, 420, label = "Superhuman Vision", color = "red"))
```
</div>

0 个答案:

没有答案