首页 > 解决方案 > bookdown 自定义块无法编译

问题描述

我正在尝试创建自定义块以在我的书中使用,用 bookdown 编写。不幸的是,在 RStudio 中单击 Build Book 不会产生该块的输出。也就是说,该块不会出现在输出 HTML 中,但本书中的其他所有内容都会出现。

我对 CSS 真的一无所知,所以决定从 bookdown 书中复制代码作为起点。以下所有文件都位于我的书的根文件夹中。

我的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 示例。

接下来,我的_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 书本身的副本。

非常感谢任何帮助!

标签: rbookdown

解决方案


推荐阅读