使用“knit html”后,内联代码不会突出显示。函数 [英] Inline codes are not highlighted after using "knit html" function in Rstudio
问题描述
我写了一个带有`引用的内联代码的 .Rmd
文件,我使用 knit html
函数将 .Rmd
文件转换为 .html
。但是,内联代码未突出显示为 stackoverflow ,我查看了 .html
文件的源代码,发现设置为
I wrote an .Rmd
file with some inline codes quoted by "`", and I used the knit html
function in Rstudio to convert the .Rmd
file to .html
. However, the inline codes were not highlighted as on stackoverflow, and I took a look at the source codes of the .html
file and found that the setting was like
tt, code, pre {
font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
}
我试图改变这个区块:
tt, code, pre {
font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
background-color: #F8F8F8;
}
但是,我不想在每次编写 .Rmd
文件到 .html
。我已经阅读R中的 knit2html
和 markdownHTMLOptions
的帮助文件,但没有找到解决方案。
However, I do not want to do such work every time after I knit the .Rmd
file to .html
. I have read the help files of knit2html
and markdownHTMLOptions
in R but found no solution. Is there any solution to this issue?
推荐答案
使用最新版本的 markdown
package on CRAN,您可以使用头
参数向HTML输出中添加其他CSS代码,例如
With the latest version of the markdown
package on CRAN, you can use the header
argument to add additional CSS code to the HTML output, e.g.
library(knitr)
knit2html(...,
header = c('<style type="text/css">', 'code{background-color: #F8F8F8;}', '</style>'))
只需将它设置为〜/ .Rprofile
中的全局选项即可:
Or just set this as a global option in your ~/.Rprofile
:
options(markdown.HTML.header = c('<style type="text/css">', 'code{background-color: #F8F8F8;}', '</style>'))
并且 markdown
您只需运行 knit2html()
,而无需明确指定头
参数
And the markdown
package will use it every time when you simply run knit2html()
without explicitly specifying the header
argument.
对于RStudio,它有点棘手。请参阅文档自定义Markdown呈现。
With RStudio, it is a little trickier. See the documentation Customizing Markdown Rendering.
这篇关于使用“knit html”后,内联代码不会突出显示。函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!