quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.74k stars 305 forks source link

document without executable code reported as containing executable code #5602

Open aronatkins opened 1 year ago

aronatkins commented 1 year ago

Bug description

Using Quarto 1.3.340 on macOS.

Given the following Markdown file named index.md, Quarto reports that the file must be named *.qmd because it contains executable code. There is no executable code in this document.

# Simple Markdown

This is a simple Markdown document containing an embedded R Markdown document.

````markdown
---
title: "embedded"
---

This is an embedded R Markdown document contained within a simple Markdown
document.

```{r setup, echo = FALSE, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

The resulting error:

quarto render index.md
#> ERROR: You must use the .qmd extension for documents with executable code.
#> 
#> Error: You must use the .qmd extension for documents with executable code.
#>     at Object.execute (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:55533:23)
#>     at renderExecute (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:86465:48)
#>     at renderFiles (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:86588:57)
#>     at async render (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:90675:21)
#>     at async Command.fn (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:90850:32)
#>     at async Command.execute (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:8437:13)
#>     at async quarto (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:127535:5)
#>     at async file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:127553:9

Encountered when trying to adapt a mkdocs site to use Quarto without performing a bunch of file renaming.

Checklist

aronatkins commented 1 year ago

Workaround: Rename index.md to index.qmd.

aronatkins commented 1 year ago
[✓] 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/RStudio.app/Contents/Resources/app/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.6
      Path: /Library/Developer/CommandLineTools/usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 3.6.3
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/3.6/Resources/library
      knitr: 1.42.8
      rmarkdown: 2.20

[✓] Checking Knitr engine render......OK
aronatkins commented 1 year ago

Workaround: Rename the file to index.qmd (which causes https://github.com/quarto-dev/quarto-cli/issues/5603), then add the YAML preamble:

---
execute:
  eval: false
---
dragonstyle commented 1 year ago

Since the cell identification / execution is being done using a text based approach, the context of being nested within the markdown cell isn't really being respected (as you discovered). The easiest way to display the syntax for executable code blocks within a markdown document like this is to escape the cell with double braces like:

# Simple Markdown

This is a simple Markdown document containing an embedded R Markdown document.

````markdown
---
title: "embedded"
---

This is an embedded R Markdown document contained within a simple Markdown
document.

```{{r setup, echo = FALSE, include=FALSE}}
knitr::opts_chunk$set(echo = TRUE)

which should resolve into the proper form and not be treated as executable...

aronatkins commented 1 year ago

Thanks @dragonstyle. Confirmed that by escaping each embedded executable chunk, the document is no longer seen as executable. The real example had quite a few more (scattered across a number of documents).

cscheid commented 1 year ago

(Apropos of our discussion of eventually using Pandoc commonmark_x AST instead of text for things like breakquartomd, this would be one of the use cases.)