I am trying to create an HTML report using RStudio, R Markdown and knitr. In the report, I would like to display the bash code. I do not want to run the code, but I would like it to be highlighted.
It was mentioned in another question , but the suggestion for me does not work. Here is what I have tried so far:
--- 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 ```
None of them give me highlighting in an HTML document. I know that this is possible because I remember that I saw him about a week ago, but I can no longer find him! Does anyone know how I can achieve this?
Thanks for reading,
Tom
Edit: I just found this answer that suggests using the following code block in .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>
This works for bash code in the document, but kills the allocation for R code!
#
r syntax-highlighting rstudio knitr r-markdown
Tom harrop
source share