自定义语法高亮显示rmd [英] custom syntax highlighting rmd

查看:114
本文介绍了自定义语法高亮显示rmd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够自定义与RMarkdown一起使用的语法突出显示,以便例如可以吸引来自某个包的函数的注意.

I would like to be able to customize the syntax highlighting used with RMarkdown so that I can, for example, draw attention to functions coming from a certain package.

我注意到knitr NEWS文档中提到了一个选项,该选项可以通过以下方式设置:

I noticed an option mentioned in the knitr NEWS document which says this option can be set via:

opts_knit$set(highr.opts = list(markup = cmd_mine))

.Rnw和.Rhtml文档.但是,当我在.Rmd文件中设置此选项时(此处简化为弄乱数字常量的高亮显示)

for .Rnw and .Rhtml documents. However, when I set this option in my .Rmd file (simplified here to messing with the highlight for numerical constants)

```{r setup, include=TRUE}
# set global chunk options
library(knitr)
opts_chunk$set(cache=TRUE)
library(highr)
cmd_mine = highr:::cmd_html
cmd_mine[rownames(cmd_mine)=="NUM_CONST", 1] <- '<span class="three">'
opts_knit$set(highr.opts = list(markup = cmd_mine))
cmd_mine
sum(1:2)
```

我看不到任何变化.这使我了解到该选项未针对.Rmd实现,或者我误解了该选项的工作方式.如果不存在,那有一天会很棒!如果可以,我将不胜感激.谢谢!

I see no change. This leads me to understand that this option is not implemented for .Rmd, or that I've misunderstood how the option works. If it doesn't exist, it'd be great if it could someday! If it does, I'd appreciate any suggestions. Thanks!

PS:实际上,我尝试为.Rhtml文档设置此设置,但也没有成功...

PS: in fact, I tried to set this for an .Rhtml document and also had no success...

推荐答案

knitr中突出显示的语法仅适用于LaTeX(.Rnw)和HTML(.Rhtml).它不适用于R Markdown(.Rmd).

The syntax highlighting in knitr only works for LaTeX (.Rnw) and HTML (.Rhtml). It does not apply to R Markdown (.Rmd).

如果它不适用于.Rhtml,则可能是错误.但是请记住,即使它起作用了,您也可能不会看到.这取决于您在CSS中为span.three定义的样式.一些屏幕截图和最少的可复制示例(加sessionInfo())将很有帮助.

If it does not work for .Rhtml, it could be a bug. But keep in mind that even if it works, you may not see it. It depends on what style you defined for span.three in CSS. Some screenshots and a minimal reproducible example (plus sessionInfo()) will be helpful.

这篇关于自定义语法高亮显示rmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆