我担心的回答是:"Markdown 的初衷就是简单,它不能做到这一点",但询问从来不会伤害任何人。
在编写 R Markdown 文档时,我可以在浏览器中查看 HTML 文件并且它看起来很棒。但是当我尝试打印它,无论是在纸上还是作为 PDF,图形中的颜色都会被打印出来,但是语法高亮却没有了。是否有一种方法可以在打印时保持语法高亮?
例如:
Minimal Example
=====
This text looks great in the file and the plot prints in color, but see commented code below.
```{r}
# this commented line will be green in the HTML file, but will be black when I print it
z <- cor(mtcars)
require(lattice) # 'require' will be blue in the HTML file, but will be black when I print it
levelplot(z)
```
在RStudio中,我点击“Knit HTML”按钮将代码转化为HTML格式后,用Chrome或Safari打开HTML没有问题。但是,如果从浏览器中打印HTML,所有的语法高亮都会丢失。
knit2HTML
按钮非常关键。问题在于markdown::markdowntoHTML
突出显示的方式。 - mnel