R语言 如何阻止夸托在渲染为html时删除gfm文件?

jgzswidk  于 2023-04-27  发布在  其他
关注(0)|答案(2)|浏览(94)

我需要同时渲染一个.qmd文件到gfm(.md)和.html,但是当我渲染.html文件时,夸托删除了现有的.md。有什么方法可以同时保持这两种格式吗?
夸托网站似乎表明这是可能的:https://quarto.org/docs/get-started/authoring/rstudio.html#rendering,但我在让它工作时遇到了麻烦。
这是我的档案:

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

到目前为止我尝试过的:

1.在RStudio中点击Render:

  • 生成一个带有gfm标签的.html文件。但是,单击gfm标签会导致一个空白页面,其中包含“未找到”。Screenshot of HTML render

我的工作目录有一个format_test.html文件,但没有format_test.md文件:

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

2.终端渲染:结果同上。

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.单独渲染:夸托删除.md文件并将其替换为.html

这个命令给了我一个format_test.md文件:

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

运行此命令将删除format_test.md,并将其替换为format_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

夸托版本:

[✓] 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
6jjcrrmo

6jjcrrmo1#

如果您想在渲染到html时获取底层的markdown文件,只需使用选项keep-md: true

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

现在有一个原因可以解释为什么在quarto render format_test.qmd --to gfm,html命令执行结束后没有得到markdown文件。夸托实际上首先生成format_test.md文件,然后继续渲染到html。在生成html输出后,它删除了markdown文件。
因此,请尝试以下命令,而不是首先指定html,然后指定gfm

quarto render format_test.qmd --to html,gfm

但如果您不想关心格式顺序,请使用专门针对htmlkeep-md: true,如下所示:

---
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>.

然后运行下面的任意一个命令都会生成html和markdown文件

quarto render format_test.qmd --to html,gfm

quarto render format_test.qmd --to gfm,html
lztngnrs

lztngnrs2#

编辑文件的顶部,使其看起来像这样:

---
title: "format_test"
format:
  html: default
  gfm: default
  execute:
    keep-md: true
---

这在execution options文档中有介绍。

相关问题