如何在Rmarkdown文档中阻止相对路径被重写为绝对路径?

时间:2016-09-14 01:09:04

标签: r knitr r-markdown pandoc

我刚刚发现在渲染Rmarkdown文档时如何处理包含../的相对路径有点不寻常。假设我的项目结构如下所示:

./
├── files/
│   ├── some_image.jpg
│   └── test.Rmd
└── some_other_image.jpg

我有一个Rmarkdown文档,我想将其呈现为包含jpegs some_image.jpgsome_other_image.jpg的HTML,如下所示:

---
title: "Path Test"
output:
  html_fragment:
    self_contained: false
    keep_md: true
---

Path without ../ is not altered
![Unaltered](some_image.jpg)

Path with ../ is converted to an absolute path!
![Altered](../some_other_image.jpg)

如果我使用rmarkdown::render("files/test.Rmd", clean = FALSE)创建HTML文档,则会生成以下HTML:

<p>Path without ../ is not altered <img src="some_image.jpg" alt="Unaltered" /></p>
<p>Path with ../ is converted to an absolute path! <img src="/home/will/test_project/some_other_image.jpg" alt="Altered" /></p>

如果查看每个图像的src属性,可以看到使用../指定的图像路径被重写为使用绝对路径!!

我的问题:为什么会这样?当我手动使用pandoc将这个相同的降价转换为HTML时,我不会发生这种情况吗?如果您检查生成的中间降价文件,some_other_image.jpg的路径仍为../some_other_image.jpg

我该怎么做才能阻止它?当然,它在我的特定机器上工作正常,但如果要将页面部署到其他地方,这是一个很大的问题。

我正在运行Rmarkdown版本1.0和R版本3.3.1进行debian测试,以防与再现相关。

0 个答案:

没有答案
相关问题