Custom CSS with knitr and markdown in R

前端 未结 2 2072
孤城傲影
孤城傲影 2021-02-06 02:23

I found this great tutorial on how to modify the css formatting of a HTML report created with markdown and knitr in Rstudio. The post can be found here.

I was hoping to

2条回答
  •  被撕碎了的回忆
    2021-02-06 03:09

    This is the method provided by RStudio: http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering

    options(rstudio.markdownToHTML = 
      function(inputFile, outputFile) {      
        require(markdown)
        markdownToHTML(inputFile, outputFile, stylesheet='custom.css')   
      }
    ) 
    

    I've never been able to get that working properly so I do it a little differently:

    I do this by creating the standard output file, then dropping the header and css code at the top in R:

    tmp <- readLines("your.html") 
    tmp <- tmp[-c(1:50)] # or however many lines it is before the css ends
    write(tmp,"your.html")
    

    Then I use pandoc to add my own css in a standalone file

    system("pandoc -s -S your.html -c your.css -o output.html")
    

提交回复
热议问题