knitr、rmarkdown、pander:最小 md -> html for <body> ...</body> only

knitr, rmarkdown, pander: Minimal md -> html for <body> ...</body> only

我有一些网站的 .md /.Rmd 文件,网页设计师在其中创建了 PHP 所有内容页面都被插入的框架,就好像它们是 只是 <body> .. </body> 之间的内容。我怎样才能转换它们 使用 knitr, rmarkdown and pander?

中的任何一个最小化 html

另一个考虑是我希望能够包含内联 图片,例如

![banner](images/banner.png)

但将这些简单地替换为 img 标签,例如

<img src="images/banner.png" alt="banner">

图像是相对于 html 文件找到的,而不是直接插入到 html 文件中。

首选解决方案是使用 YAML header 类似

---
output:
  html_document:
     body_only         
---

或者,任何其他可以轻松编译其中的 collection 的东西 html 使用 R Studio。

两个 options 是这个问题的关键:output: html_fragment 获取片段而不是完整文档,self_contained: false 获取引用图像而不是数据 URI。

---
output: 
  html_fragment:
    self_contained: false
---

Some text. *Important*.

```{r, echo = FALSE}
plot(1)
```

![Other Image](path/to/other/image.jpg)

运行 rmarkdown::render 此 RMD 文件给出:

<p>Some text. <em>Important</em>.</p>
<p><img src="frag_files/figure-html/unnamed-chunk-1-1.png" title="" alt="" width="672" /></p>
<p><img src="path/to/other/image.jpg" alt="Other Image" /></p>