Skip to content

The characters between inverted commas printed with # | output: asis and format: gfm vary depending on random factors. #12854

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

Open
3 tasks done
JosephBARBIERDARNAL opened this issue May 29, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@JosephBARBIERDARNAL
Copy link

JosephBARBIERDARNAL commented May 29, 2025

I have:

  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide

Bug description

I'm trying to generate a Markdown file with format: gfm. My Quarto file basically contains Python code that prints "asis" a few strings that should be quoted with ".

The issue is that the Markdown output file actually uses the following quote symbols: and instead of ".

This might happen or not in different scenarios. Sometimes it does, sometimes it doesn't.

The only case I've been able to reliably reproduce is when there's also an R code chunk. In that case, it uses the correct quote symbol ("). But if I remove the R chunk, it switches to the other ones.

I'm pretty sure the "error" (if that's what it is) could be reproduced without an R code chunk, but I haven't been able to pinpoint exactly when it happens.

A similar thing happens with the ' symbol, see the reprex.

Steps to reproduce

  • Case 1 (with R chunk): python output is valid, it actually put the right symbols (' and ")
---
format: gfm
---


```{python}
# | output: asis

x = "cat"
print(f"'{x}'")
print(f'"{x}"')
```

```{r}
# | output: asis

x = "cat"
print(glue::glue("'{x}'"))
print(glue::glue('"{x}"'))
```
  • Case 2 (without R chunk): python output is not valid, it puts the / and / symbols instead
---
format: gfm
---


```{python}
# | output: asis

x = "cat"
print(f"'{x}'")
print(f'"{x}"')
```

Actual behavior

It prints the "wrong" (at least unexpected) symbols (/ and /).

Output of case 2:

``` python
x = "cat"
print(f"'{x}'")
print(f'"{x}"')
```

‘cat’ “cat”

Expected behavior

I wish it always output the " (and ') symbols, as this leads to unexpected behaviors in some use cases.

Maybe I can just run a post-render script to replace those symbols, but it still feels like a bug to me.

expected output of case 2:

``` python
x = "cat"
print(f"'{x}'")
print(f'"{x}"')
```

'cat' "cat"

Your environment

  • OS: macos sequoia 15.5
  • IDE: Positron 2025.05.0 (Universal) build 142

Quarto check output

Quarto 1.7.31
[✓] Checking environment information...
Quarto cache location: /Users/josephbarbier/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.6.3: OK
Dart Sass version 1.85.1: OK
Deno version 1.46.3: OK
Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.7.31
Path: /Applications/quarto/bin

[✓] Checking tools....................OK
TinyTeX: (not installed)
Chromium: (not installed)

[✓] Checking LaTeX....................OK
Using: Installation From Path
Path: /Library/TeX/texbin
Version: 2022

[✓] Checking Chrome Headless....................OK
Using: Chrome found on system
Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Source: MacOS known location

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

[✓] Checking Python 3 installation....OK
Version: 3.13.1
Path: /Users/josephbarbier/Desktop/morethemes/.venv/bin/python3
Jupyter: 5.8.1
Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
Version: 4.5.0
Path: /Library/Frameworks/R.framework/Resources
LibPaths:
- /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
knitr: 1.50
rmarkdown: 2.29

[✓] Checking Knitr engine render......OK

Other

I tried to add:

---
format: gfm
post-render: sed -i '' 's/[“”]/"/g' docs/index.md
---

But that does not fix the issue.

@JosephBARBIERDARNAL JosephBARBIERDARNAL added the bug Something isn't working label May 29, 2025
@mcanouil
Copy link
Collaborator

mcanouil commented Jun 1, 2025

# | is only valid when using the Jupyter engine.
When mixing R and Python code, the engine, if not set, is knitr which relies on reticulate to evaluate Python code.

The same result can be observed using Jupyter for the Python code because asis means "read as Markdown".

The "curly" quotes are a Pandoc feature smart that you can disable:

---
format: gfm
from: markdown-smart
---

```{r}
#| output: asis
x = "cat"
print(glue::glue("'{x}'"))
print(glue::glue('"{x}"'))
```

The Python code via reticulate is actually not treated "as is" in your example, as you can see using keep-md: true. This is because, knitr/reticulate does not consider # | as valid YAML option.

Note that post-render is a project option not a document option as described in the documentation: https://quarto.org/docs/projects/scripts.html#pre-and-post-render

@cderv
Copy link
Collaborator

cderv commented Jun 2, 2025

I am now puzzled if # | should be supported for knitr and Python cell ... 🤔

Why do we support that ? for ruff or black formatter ?

@JosephBARBIERDARNAL
Copy link
Author

The "curly" quotes are a Pandoc feature smart that you can disable:

That's good to know, it's exactly what I need here, thanks.

@mcanouil
Copy link
Collaborator

mcanouil commented Jun 2, 2025

Why do we support that ? for ruff or black formatter ?

Yes, at the time, Black's maintainers rejected the request to add an exception thus my attempt at protecting the YAML options/comments in:

Shiny Live Python also supports the # | syntax since few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants