Closed amarakon closed 2 years ago
If I add a code block in an R Markdown document, the resulting Markdown file will have tabs replaced with four spaces in that code block.
Are you sure that after typing the tabs in the .Rmd
documents, it is still tabs in the .Rmd
documents ? I mean before any conversion by Rmarkdown.
I ask because IDE are able to transformed tabs to space in their editor for code
In IDE you can usually shows the whitespaces characters
You'll see that for example dots for spaces and dashes for tabs.
If this is happening then your source files does not contains tabs, but spaces. hence the result contains spaces.
Otherwise, please can you share a .Rmd
document with the tabs for us to check this out.
Thank you
Are you sure that after typing the tabs in the
.Rmd
documents, it is still tabs in the.Rmd
documents ? I mean before any conversion by Rmarkdown.
Sorry, that is not what I meant. I do not use the RStudio IDE. I meant, when I insert a tab character in a code chunk, the .md
file (generated by rmarkdown::render()
), will have four spaces instead of that tab character.
.Rmd
:
example code chunk
^
|----- Here is a tab character
.md
:
example code chunk
^
|----- Here are four spaces
I forgot to mention that this seems to happen in blogdown when blogdown.method
is set to "markdown"
.
Sorry, that is not what I meant. I do not use the RStudio IDE.
Ok good. I wanted to check. Also this could happen with any other IDE using the same feature.
I forgot to mention that this seems to happen in blogdown
So you confirm this does not happen in regular R Markdown document ? Like with html_document
?
If you can share a reproducible example to be sure we are using the same thing.
I believe when using Pandoc to convert, by default tabs are converted to spaces, unless the --preserve-tabs
option is passed.
https://pandoc.org/MANUAL.html#option--preserve-tabs We don't set this option by default in blogdown I believe.
Using pandoc_args
from html_page()
format should allow you to specify that when using HTML format as output.
You said you are using Markdown, and in that case we run Pandoc in specific case to convert from knitted md to another md. And in that case, not possible to customize...
I'll move this to blogdown if you confirm this is only for this type of output, and look closer.
So you confirm this does not happen in regular R Markdown document ? Like with html_document ? If you can share a reproducible example to be sure we are using the same thing.
This does happen in a regular R Markdown document, but it can be easily changed by using the preserve-tabs
Pandoc argument:
---
title: Indent Test
output:
html_document:
pandoc_args: --preserve-tabs
---
example code block with indent
However, in blogdown with blogdown.method = "markdown"
, it does not use Pandoc. Instead, it just converts the .Rmd
file to a .md
file then uses a Markdown interpreter like Goldmark to interpret it into HTML. Pandoc is not used in this case. So I think it is an issue with just blogdown.
This does happen in a regular R Markdown document, but it can be easily changed by using the preserve-tabs Pandoc argument
Thanks for confirming that --preserve-tabs
in the source of the observed behavior.
However, in blogdown with blogdown.method = "markdown", it does not use Pandoc. Instead, it just converts the .Rmd file to a .md file then uses a Markdown interpreter like Goldmark to interpret it into HTML. Pandoc is not used in this case. So I think it is an issue with just blogdown.
blogdown uses knitr to convert for Rmd to .md, and my use Pandoc in certain case to handle some specific pandoc-related content that could have been inserted in the document. In that case, pandoc is use to convert from md
to md
. However, there is no way currently to pass some option to this.
@yihui I see several options here:
We could default to --preserve-tabs
in blogdown md conversion
We could add somewhere a preserve_tabs
option to be set to TRUE and add the flag.
We could add a way to pass any option to Pandoc during to the md to md conversion.
md_page()
format that would allow to be tweaked and options passed to it. What do you think ?
We maybe could move this to blogdown repo
I like the idea of a preserve_tabs
option.
I don't want to make this too general and complicated, but just added --preserve-tabs
to the default value of pandoc_args
. I don't think this is an option that is going to be widely used, so I tend to keep it simple for now. Thanks!
BTW, if anyone doesn't like this change (i.e., prefers tabs to be replaced by spaces), they have two choices. One is to use spaces instead of tabs in the input document, and the other is to provide custom pandoc_args
values to blogdown::html_page
. I guess the demand should be rare.
If I add a code block in an R Markdown document, the resulting Markdown file will have tabs replaced with four spaces in that code block. I don't know why this is the default behaviour, and I wish there was a way to change it. Is there currently a way to make it so that tabs are preserved in code blocks? And why are they not by default?
As a reference, see this topic on community.rstudio.com: https://community.rstudio.com/t/how-can-i-prevent-r-markdown-from-turning-tabs-to-spaces-in-code-blocks/152691/8
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
[x] formatted your issue so it is easier for us to read?
[x] included a minimal, self-contained, and reproducible example?
[x] pasted the output from
xfun::session_info('rmarkdown')
in your issue?[x] upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
[x] installed and tested your bug with the development version of the rmarkdown package using
remotes::install_github("rstudio/rmarkdown")
?Output of
xfun::session_info("rmarkdown")
: