Repository navigation
The characters between inverted commas printed with # | output: asis and format: gfm vary depending on random factors. #12854
Description
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.
Activity
mcanouil commentedon Jun 1, 2025
# |is only valid when using the Jupyter engine.When mixing R and Python code, the engine, if not set, is
knitrwhich relies onreticulateto evaluate Python code.The same result can be observed using Jupyter for the Python code because
asismeans "read as Markdown".The "curly" quotes are a Pandoc feature
smartthat you can disable:The Python code via
reticulateis actually not treated "as is" in your example, as you can see usingkeep-md: true. This is because,knitr/reticulatedoes not consider# |as valid YAML option.Note that
post-renderis a project option not a document option as described in the documentation: https://quarto.org/docs/projects/scripts.html#pre-and-post-rendercderv commentedon 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 commentedon Jun 2, 2025
That's good to know, it's exactly what I need here, thanks.
mcanouil commentedon Jun 2, 2025
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.cscheid commentedon Jun 11, 2025
For everyone else reading this, the
post-renderoption does not work like the OP suggested:@JosephBARBIERDARNAL I suspect you asked an LLM about this. I would strongly urge you not to do that with Quarto documents, because LLMs are quite prone to hallucinating YAML options that don't exist, and you'll end up more confused than where you started.
JosephBARBIERDARNAL commentedon Jun 11, 2025
Yes I know they are not the best for quarto... But in this case I just saw this in the doc and just copied
pre-renderwithout actually reading the doc (which might be even worse than asking an LLM actually).JosephBARBIERDARNAL commentedon Jun 11, 2025
By the way, this goes beyond the scope of the issue, but are there any plans to add options at document level for pre/post-rendering scripts?
cscheid commentedon Jun 11, 2025