knitr,rmarkdown,pander:Minimal md - > html仅适用于......

时间:2015-12-13 21:51:38

标签: php html rstudio knitr

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

另一个考虑因素是我希望能够包含内联 图像,如

![banner](images/banner.png)

但是这些只是替换为img标记,例如

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

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

首选解决方案是使用类似

的YAML标头
---
output:
  html_document:
     body_only         
---

或者,其他任何可以轻松编译这些集合的东西 使用R Studio进行html。

1 个答案:

答案 0 :(得分:3)

两个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)

在此RMD文件上运行rmarkdown::render会给出:

<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>