我正在尝试使用RStudio,R Markdown和knitr生成HTML报告.在报告中我想显示一些bash代码.我不想运行代码,但我希望它能够突出显示.
原文链接:https://www.f2er.com/bash/387188.html它已在another question中提到,但那里的建议对我不起作用.这是我到目前为止所尝试的内容:
--- title: "bash highlighting?" output: html_document --- ```{r,engine = 'bash',eval = FALSE} for foo in (ls bar) do echo $foo done ``` ```{bash,eval = FALSE} for foo in (ls bar) do echo $foo done ```
这些都没有让我在HTML文档中突出显示.我知道这是可能的,因为我记得在大约一周前的某个地方看到它,但我再也找不到它了!有谁知道我怎么能实现它?
谢谢阅读,
汤姆
编辑:我刚刚找到this answer,建议在.Rmd中使用以下代码块
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script> <script> $(document).ready(function() { $('pre code').each(function(i,e) {hljs.highlightBlock(e)}); }); </script>
## R version 3.2.0 (2015-04-16) ## Platform: x86_64-pc-linux-gnu (64-bit) ## Running under: Ubuntu 14.04.2 LTS ## ## locale: ## [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C ## [3] LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8 ## [5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8 ## [7] LC_PAPER=en_AU.UTF-8 LC_NAME=C ## [9] LC_ADDRESS=C LC_TELEPHONE=C ## [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C ## ## attached base packages: ## [1] stats graphics grDevices utils datasets methods base ## ## loaded via a namespace (and not attached): ## [1] formatR_1.2 tools_3.2.0 htmltools_0.2.6 yaml_2.1.13 ## [5] rmarkdown_0.5.1 knitr_1.10 stringr_0.6.2 digest_0.6.8 ## [9] evaluate_0.7