Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandoc 2 changes the behavior of knitr chunk option indent for html_document #1557

Closed
3 tasks done
jdblischak opened this issue Mar 26, 2019 · 5 comments
Closed
3 tasks done

Comments

@jdblischak
Copy link
Contributor

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

The hidden knitr chunk option indent behaves differently for html_document() between pandoc 1 and 2. I realize this is a minor issue since indent is only supposed to be used for markdown output. Also, it could be argued that the pandoc 2 behavior is preferred. But since I observed it, I wanted to share the result in case anyone depended on the pandoc 1 behavior.

Reproducible Rmd file

The examples below use the following Rmd file, which I saved as test-indent.Rmd:

---
output:
  html_document:
    keep_md: true
---

```{r example, indent="  "}
1 + 1
```

pandoc 1 preserves the indentation in the HTML file

Rendering this document with pandoc 1.19.2.1 preserves the indentation in the HTML file:

$ Rscript -e 'rmarkdown::render("test-indent.Rmd", quiet = TRUE)'
$ grep '1 + 1' test-indent.*
test-indent.html:<p><code>r   1 + 1</code></p>
test-indent.md:  1 + 1
test-indent.Rmd:1 + 1

which causes the code chunks to be malformed (screenshot below):

indent-pandoc1

> xfun::session_info(c("knitr", "rmarkdown"))
R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3 digest_0.6.18   evaluate_0.13   glue_1.3.1     
  graphics_3.5.1  grDevices_3.5.1 highr_0.8       htmltools_0.3.6
  jsonlite_1.6    knitr_1.22      magrittr_1.5    markdown_0.9   
  methods_3.5.1   mime_0.6        Rcpp_1.0.1      rmarkdown_1.12 
  stats_3.5.1     stringi_1.4.3   stringr_1.4.0   tinytex_0.11   
  tools_3.5.1     utils_3.5.1     xfun_0.5        yaml_2.2.0     

Pandoc version: 1.19.2.1

For conda users, I created this environment with the following command:

conda create -y -n test-pandoc1 -c conda-forge pandoc=1.19.2.1 r-rmarkdown

pandoc 2 removes the indentation in the HTML file

Rendering this document with pandoc 2.7.1 removes the indentation in the HTML file:

$ Rscript -e 'rmarkdown::render("test-indent.Rmd", quiet = TRUE)'
$ grep '1 + 1' test-indent.*
test-indent.html:<pre class="r"><code>1 + 1</code></pre>
test-indent.md:  1 + 1
test-indent.Rmd:1 + 1

which causes the code chunks to properly formatted (screenshot below):

indent-pandoc2

> xfun::session_info(c("knitr", "rmarkdown"))
R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3 digest_0.6.18   evaluate_0.13   glue_1.3.1     
  graphics_3.5.1  grDevices_3.5.1 highr_0.8       htmltools_0.3.6
  jsonlite_1.6    knitr_1.22      magrittr_1.5    markdown_0.9   
  methods_3.5.1   mime_0.6        Rcpp_1.0.1      rmarkdown_1.12 
  stats_3.5.1     stringi_1.4.3   stringr_1.4.0   tinytex_0.11   
  tools_3.5.1     utils_3.5.1     xfun_0.5        yaml_2.2.0     

Pandoc version: 2.7.1

For conda users, I created this environment with the following command:

conda create -y -n test-pandoc2 -c conda-forge pandoc=2 r-rmarkdown
@atusy
Copy link
Contributor

atusy commented May 22, 2019

I guess the behavior in Pandoc 2 is the way supposed to be.
knitr manual says

Currently this option is only used to indent markdown output, because leading white spaces have special meanings in markdown. https://yihui.name/knitr/options/#code-decoration

Utilizing "special meaning" by indent = " " (4 spaces) will output markdown like

    ```r
    1 + 1
    ```

and output html preserving fences like below.

```r
1 + 1
```

I guess Pandoc 1.x is outputing something like

```r
    1 + 1
```

If so, there is no way to use "special meaning" of indents.

Would you check indents of fences?

@jdblischak
Copy link
Contributor Author

Would you check indents of fences?

@atusy I'm not exactly sure what you are asking. Do you want to know how the backticks are indented in the Markdown file? This result has not changed between Pandoc 1 and 2. No matter which you use, the output Markdown file will have everything indented: the code chunk, the results it creates, and the backticks around each. See below.

Is that what you wanted to know, or did you have another question?

Pandoc 1

$ pandoc -v | head -n 1
pandoc 1.19.2.1
$ cat test-indent.md 
---
output:
  html_document:
    keep_md: true
---

  
  ```r
  1 + 1
  ```
  
  ```
  ## [1] 2
  ```

Pandoc 2

$ pandoc -v | head -n 1
pandoc 2.7.2
$ cat test-indent.md 
---
output:
  html_document:
    keep_md: true
---

  
  ```r
  1 + 1
  ```
  
  ```
  ## [1] 2
  ```

@atusy
Copy link
Contributor

atusy commented May 23, 2019

Yes, that's what I meant.

It seems like a change in Pandoc 2.0.2

Markdown reader:

Allow fenced code blocks to be indented 1-3 spaces (#4011). This brings our handling of them into alignment with CommonMark’s.

https://pandoc.org/releases.html#pandoc-2.0.2-12-november-2017

@jdblischak
Copy link
Contributor Author

It seems like a change in Pandoc 2.0.2

@atusy Thanks for investigating! It does appear that the change in the behavior of indent arose from the changes introduced in response to Issue jgm/pandoc#4011.

Since this change in behavior for processing indented code fences is documented in this thread and the main pandoc repository, hopefully this is sufficient explanation to anyone searching for this.

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants