Highlighting bash code with knitr / rmarkdown

前端 未结 2 1767
春和景丽
春和景丽 2020-12-31 14:20

I\'m trying to generate an HTML report using RStudio, R Markdown and knitr. In the report I would like to display some bash code. I do not want to run the code

2条回答
  •  春和景丽
    2020-12-31 15:01

    OK, figured it out thanks to the comments. It seems it's RStudio which is not playing nice with the highlighting. When I keep the intermediate markdown file as in.md:

    ---
    title: "Bash Highlighting"
    output:
      html_document:
        keep_md: true
    ---
    
    ```{r, engine = 'bash', eval = FALSE}
    for foo in (ls bar)
    do
      echo $foo
    done
    ```
    

    then convert to html with pandoc using e.g. the CSS from BioConductor:

    pandoc -s in.md \
        -c https://hedgehog.fhcrc.org/bioconductor/branches/RELEASE_3_1/madman/Rpacks/BiocStyle/inst/resources/html/bioconductor.css \
        -t html -o out.html
    

    I get nice code highlighting for R and bash.

    Thanks!

提交回复
热议问题