Exact usage for hidden indent option with knitr

时间:2015-07-28 22:14:58

标签: markdown knitr r-markdown

I'm trying to render rmarkdown to markdown and implement the example for the hidden indentation option from Yihui Xie's documentation for knitr:

There is a hidden option indent which stores the possible leading white spaces of the chunk, e.g. for the chunk below, indent is a character string of two spaces:

  ```{r}
  rnorm(10)
  ```

Which I interpret to mean simply add two spaces before each line in the code as I entered above. However, when I knit the document the code block is not recognized because of the leading spaces. Obviously I am not understanding the correct way to implement this option.

I want to do this because I'm writing a book with Leanpub and I need to render rmarkdown to markdown. The default four spaces leads to a code block with Leanpub's markdown interpreter, but doesn't put code and output in nice boxes the way rmarkdown/knitr users are used to. If I can control the whitespace in markdown, I will have more control over how my code and output looks. If they took html files as a normal part of their workflow it would be easy, but this is not fully supported.

1 个答案:

答案 0 :(得分:1)

缩进选项实际上是代码块的一个选项。如在

 ```{r,  indent=" "}
 code
 ```

在渲染文档中的代码之前添加一个字符空间。现在似乎很明显。但是,这并不能解决我的首要问题。

我确实找到了一个简单的解决方案来降低降价问题。只需在代码块周围放置转义波形符。

在rmarkdown中

 \~\~\~\~\~ 
 ```{r}
  code
 ```
 \~\~\~\~\~

呈现为

 ~~~~~ 

 code

 executed code

 ~~~~~
降价文件中的

。然后Leanpub的降价在代码前后放置水平线。不完全是我正在寻找的盒子,但它的工作原理。