Search code examples
rquarto

How to stop Quarto from deleting gfm files when rendering to html?


I need to render a .qmd file simultaneously to both gfm (.md) and .html, but quarto deletes the existing .md when I render the .html file. Is there any way to keep both formats?

The Quarto website seems to suggest that it's possible: https://quarto.org/docs/get-started/authoring/rstudio.html#rendering, but I'm having trouble getting it to work.

This is my file:

format_test.qmd

---
title: "format_test"
format:
  html: default
  gfm: default
---

## Quarto

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

## Running Code

When you click the **Render** button a document will 
be generated that includes both content and the output 
of embedded code. You can embed code like this:

```{r}
1 + 1

What I've tried so far:

1. Clicking Render in RStudio:

  • Produces a .html file with a gfm tab. However, clicking on the gfm tab results in a blank page with the phrase "Not found". Screenshot of HTML render

My working directory has a format_test.html file, but not the format_test.md file:

list.files()
[1] "format_test_files" "format_test.html"  "format_test.qmd"  
[4] "format_test.Rproj"

2. Rendering via the terminal: Same result as above.

quarto render format_test.qmd --to gfm,html
processing file: format_test.qmd
                                                                                                            
output file: format_test.knit.md

pandoc 
  to: html
  output-file: format_test.html
  standalone: true
  section-divs: true
  html-math-method: mathjax
  wrap: none
  default-image-extension: png
  
metadata
  document-css: false
  link-citations: true
  date-format: long
  lang: en
  title: format_test
  


processing file: format_test.qmd
                                                                                                            
output file: format_test.knit.md

pandoc 
  to: >-
    commonmark+autolink_bare_uris+emoji+footnotes+gfm_auto_identifiers+pipe_tables+strikeout+task_lists+tex_math_dollars
  output-file: format_test.md
  standalone: true
  default-image-extension: png
  toc: true
  number-sections: true
  
metadata
  title: format_test
list.files()
[1] "format_test_files" "format_test.html"  "format_test.qmd"  
[4] "format_test.Rproj"

3. Rendering them individually: Quarto deletes the .md file and replaces it with .html

This command gives me a format_test.md file:

quarto render format_test.qmd --to gfm
processing file: format_test.qmd

output file: format_test.knit.md

pandoc
to: \>-
commonmark+autolink_bare_uris+emoji+footnotes+gfm_auto_identifiers+pipe_tables+strikeout+task_lists+tex_math_dollars
output-file: format_test.md
standalone: true
default-image-extension: png
toc: true
number-sections: true

metadata
title: format_test

Output created: format_test.md
ls

format_test.Rproj       format_test.md          format_test.qmd

Running this command deletes format_test.md, and replaces it withformat_test.html.


quarto render format_test.qmd --to html
processing file: format_test.qmd

output file: format_test.knit.md

pandoc
to: html
output-file: format_test.html
standalone: true
section-divs: true
html-math-method: mathjax
wrap: none
default-image-extension: png

metadata
document-css: false
link-citations: true
date-format: long
lang: en
title: format_test

Output created: format_test.html
ls
format_test.Rproj       format_test.qmd
format_test.html        format_test_files

sessionInfo:

R version 4.2.2 (2022-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
\[1\] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
\[1\] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
\[1\] compiler_4.2.2  tools_4.2.2     rstudioapi_0.14 knitr_1.42  
\[5\] xfun_0.37

Quarto version:

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.340
      Path: /Applications/quarto/bin

Solution

  • If you want to get the underlying markdown file when rendering to html, simply use the option keep-md: true,

    ---
    title: "format_test"
    format: html
    keep-md: true
    ---
    

    Now there's a reason why you are not getting the markdown file after the command quarto render format_test.qmd --to gfm,html ends executing. Quarto actually generates the format_test.md file at first, then it continues to the rendering to html. After it produces the html output, it then removes the markdown file.

    Therefore, try the following command instead specifying the html at first and then gfm,

    quarto render format_test.qmd --to html,gfm
    

    But if you do not want to care about the format order, use the keep-md: true specifically for html format as follows,

    ---
    title: "Untitled"
    format:
      html: 
        keep-md: true
      gfm: default
    ---
    
    ## Quarto
    
    Quarto enables you to weave together content and executable code
    into a finished document. To learn more about Quarto 
    see <https://quarto.org>.
    
    

    Then running either of the commands below generates both of the html and markdown files,

    quarto render format_test.qmd --to html,gfm
    

    or

    quarto render format_test.qmd --to gfm,html