Skip to content

[knitr] Correctly write markdown content to rmd intermediate on windows#7126

Merged
cderv merged 1 commit intomainfrom
windows/fix-rmd-intermediate
Oct 4, 2023
Merged

[knitr] Correctly write markdown content to rmd intermediate on windows#7126
cderv merged 1 commit intomainfrom
windows/fix-rmd-intermediate

Conversation

@cderv
Copy link
Collaborator

@cderv cderv commented Oct 4, 2023

On Windows markdown content parsed by Quarto from .qmd file is passed to R part of code base as a single string using windows EOL (\r\n). Previously, using base::write() was writing an empty line between each original linebreak because it is based on cat() and does write linebreak for \r and \n. We need the rmd intermediate as close as possible to the input .qmd

Opening this PR to run tests but I believe this will be ok and this change is for the best.

Example

Take this simple .qmd

---
title: "Test"
format: html
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.


```{r}
1 + 1
```

What Quarto is passing to R is this markdown content

markdown <-
"---\r\ntitle: \"Test\"\r\nformat: html\r\n---\r\n\n\r\n## Quarto\r\n\r\nQuarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.\r\n\r\n\r\n\n```{r}\r\n1 + 1\r\n```\r\n"

Note the \r\n.

This would be the content of .rmarkdown intermediate used by rmarkdown::render() - see all the new lines.

---

title: "Test"

format: html

---




## Quarto



Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.






```{r}

1 + 1

```

I am surprised that this is has not create any issue, probably because we only knit() using rmarkdown but still.

This PR fix this on the R side by making sure we write markdown the right way in the .rmarkdown input file.

We could also normalize markdown to have only \n and no \r\n EOL.

On Windows `markdown` content parsed by Quarto from .qmd file is passed to R part of code base as a single string using windows EOL (`\r\n`).
Previously, using base::write() was writing an empty line between each original linebreak because it is based on `cat()` and does write linebreak for `\r` and `\n`.  We need the rmd intermediate as close as possible to the input .qmd
@cderv cderv merged commit 1d7e53c into main Oct 4, 2023
@cderv cderv deleted the windows/fix-rmd-intermediate branch October 4, 2023 15:58
@cderv cderv added this to the v1.4 milestone Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant