Skip to content

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

Open

Description

@JosephBARBIERDARNAL

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

  1. mcanouil commented on Jun 1, 2025

    @mcanouil
    Collaborator

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

  2. cderv commented on Jun 2, 2025

    @cderv
    Member

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

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

  3. JosephBARBIERDARNAL commented on Jun 2, 2025

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

  4. mcanouil commented on Jun 2, 2025

    @mcanouil
    Collaborator

    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.

  5. cscheid commented on Jun 11, 2025

    @cscheid
    Member

    For everyone else reading this, the post-render option does not work like the OP suggested:

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

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

  6. JosephBARBIERDARNAL commented on Jun 11, 2025

    @JosephBARBIERDARNAL
    Author

    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-render without actually reading the doc (which might be even worse than asking an LLM actually).

  7. JosephBARBIERDARNAL commented on Jun 11, 2025

    @JosephBARBIERDARNAL
    Author

    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?

  8. cscheid commented on Jun 11, 2025

    @cscheid
    Member
    • we want to do it
    • we have started combining the logic of project rendering and single-file rendering
    • but the code paths are still sufficiently different that we're not ready to do it
  9. added this to the Future milestone on Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions