我正在尝试创建自定义块,以便在书中使用。不幸的是,单击RStudio中的Build Book不会产生块的输出。也就是说,该块不会出现在输出HTML中,但书中的其他所有内容都会出现。
我对CSS一无所知,因此决定将书籍中的代码复制为起点。以下所有文件都位于我的图书的根文件夹中。
我的style.css
文件如下所示:
.rmdcaution, .rmdimportant, .rmdnote, .rmdtip, .rmdwarning {
padding: 1em 1em 1em 4em;
margin-bottom: 10px;
background: #f5f5f5 5px center/3em no-repeat;
}
.boo {
padding: 1em 1em 1em 4em;
margin-bottom: 10px;
background: #f5f5f5;
position:relative;
}
div.boo:before {
content: "\f518";
font-family: FontAwesome;
left:10px;
position:absolute;
top:0px;
font-size: 45px;
}
p.caption {
color: #777;
margin-top: 10px;
}
p code {
white-space: inherit;
}
pre {
word-break: normal;
word-wrap: normal;
}
pre code {
white-space: inherit;
}
第一个样式块是从bookdown书中复制而第二个是基于SO示例here。
接下来,我的_output.yml
文件如下所示:
bookdown::gitbook:
css: [style.css, fontawesome.min.css]
config:
toc:
before: |
<li><a href="./">Surviving Statistics</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
download: ["pdf", "epub"]
最后,我在我的rmd文件中调用块:
```{block, type='boo'}
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.
```
```{block2, type='rmdnote'}
If you are planning on printing your book to PDF, you will need a LaTeX distribution. We recommend that you install TinyTeX (which includes XeLaTeX): <https://yihui.name/tinytex/>.
```
如您所见,第一个是上述SO示例的副本,第二个是Bookdown书本身的副本。
非常感谢任何帮助!