如何在rmarkdown中使用自定义pygments语法高亮显示?通过pygments,我创建了一个文件nice.py
:
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic
class niceStyle(Style):
default_style = ""
styles = {
Operator: "bold #818181",
Number: "bold #0000cf",
Generic: "#000000",
Comment: 'italic #08a542',
Keyword: 'bold #0000cf',
Name: '#f00',
Name.Function: '#0000cf',
Name.Class: 'bold #0f0',
String: '#ff7f50'
}
现在我想在rmarkdown中使用它来进行语法高亮显示:
---
output: beamer_presentation
# highlight: nice
---
```{r}
# Comment
f <- function(x = 10, y = "abc") {
paste0(x, y)
}
f()
```
也许我可以在knitr::knit_hooks$set
中添加此内容?还是有另一种方式?