我正在使用 https://github.com/laozhu/hugo-nuo 的主题
我试图在 RMarkdown 文件中包含 python 代码(对我来说 eval=TRUE 或 FALSE 并不重要)。输出文件由 R blogdown (html) 编译为帖子。但是,格式对读者不太友好(纯文本)。我想知道是否有任何方法可以格式化代码块? (不同颜色、粗体、斜体或在代码之间添加空行?)谢谢。
```{python eval=FALSE}
```
最佳答案
默认的 blogdown 主题(以及其他几个 Hugo 主题)使用 highlight.js它允许您突出显示 176 种语言(包括 Python)的代码。
也就是说,在我看来,您使用的主题并非如此。您需要:
- 下载 highlight.js
- 保存
highlight.pack.js
进入themes/hugo-nuo/static/js - 将您喜欢的 css 格式(这些是颜色选项)复制到 themes/hugo-nuo/static/css
- 关于
header.html
或head.html
文件(取决于链接文件的文件)编写以下内容并适当更改“the-css-you-chose”。
<link rel="stylesheet" href="{{"css/the-css-you-chose.css" | absURL}}" rel="stylesheet" id="theme-stylesheet">
<script src="{{ "js/highlight.pack.js" | absURL }}"></script>
<script>hljs.initHighlightingOnLoad();</script>
您可以关注Amber Thomas' blog了解更多信息。
关于python - 如何在 R blogdown (RMarkdown) 中格式化代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48778937/