creating custom blocks in RStudio's bookdown

前端 未结 1 580
陌清茗
陌清茗 2021-02-03 11:27

I\'m experimenting with the great new package bookdown to create a gitbook-style book using RMarkdown within RStudio. See here.

My question is about creating custom bloc

1条回答
  •  梦谈多话
    2021-02-03 12:22

    Thanks to @Frank's tip (see his solution for using local images), I was able to come up with the following.

    I added this to the style.css file in the root of my book's directory based on this SO answer and this specific example:

    .rmdcomment {
      padding: 1em 1em 1em 4em;
      margin-bottom: 10px;
      background: #f5f5f5;
      position:relative;
    }
    
    .rmdcomment:before {
        content: "\f075";
        font-family: FontAwesome;
        left:10px;
        position:absolute;
        top:0px;
        font-size: 45px;
     }
    

    I got the value f075 for the comment icon from this FontAwesome cheatsheet.

    Then I downloaded the CSS toolkit from FontAwesome and copied the font-awesome.min.css file into the root of my book directory. I added the following to my output.yml file (in the template I started with, style.css, toc.css was already present):

    bookdown::html_book:
      css: [style.css, toc.css, font-awesome.min.css]
    

    Finally, I inserted a code chunk into my Rmd file using the type option:

    ```{block, type='rmdcomment'}
    Some text for this block. Some text for this block. Some text for this block. Some text for this block. Some text for this block. Some text for this block.
    ```
    

    0 讨论(0)
提交回复
热议问题