0
votes

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

1 Answers

1
votes

The indent option is literally a option to the code chunk. As in

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

adds one character space before the code in the rendered document. Seems obvious now. However, this wasn't really a solution to my overarching problem.

I did find a simple solution for the rmarkdown to markdown problem though. Simply place escaped tilde's around the code block.

In rmarkdown

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

renders as

 ~~~~~ 

 code

 executed code

 ~~~~~

in the markdown document. Then Leanpub's markdown puts horizontal lines before and after the code. Not exactly the box I was looking for but it works.