Skip to content

Preserve whitespace for Quarto cell option comments - #25641

Merged
MichaReiser merged 3 commits into
astral-sh:mainfrom
DavisVaughan:feature/quarto-hash-pipe
Jun 5, 2026
Merged

Preserve whitespace for Quarto cell option comments#25641
MichaReiser merged 3 commits into
astral-sh:mainfrom
DavisVaughan:feature/quarto-hash-pipe

Conversation

@DavisVaughan

Copy link
Copy Markdown
Contributor

Summary

Part of #6140, which is nicely summarized into 2 parts here #6140 (comment)

I saw that you all now support formatting markdown files (#22470) and can support .qmd via some user configuration (#23218, #23384, #23572).

Since ruff can now directly format a .qmd, I thought it would be nice if this bug was fixed:

With ruff.toml of:

extension = { qmd = "markdown" }

test.qmd:

This is my qmd


```{python}
#| echo: true

1 + 1
```

A call to ruff format test.qmd --preview results in

This is my qmd


```{python}
# | echo: true

1 + 1
```

Note how the special quarto code cell directive #| became # |.

Note this would diverge from black's behavior. There was a request to change this in black, but it was closed psf/black#3557. But I'm hoping that the fact that ruff can support qmds directly may make this compelling enough for ruff to diverge?

Test Plan

Added a new snapshot test file.

Note the the black compatibility file comments.py does exist already, but it did not feel appropriate to add this there.

@DavisVaughan
DavisVaughan requested a review from MichaReiser as a code owner June 4, 2026 17:44
@ntBre ntBre added the formatter Related to the formatter label Jun 4, 2026
@MichaReiser

MichaReiser commented Jun 4, 2026

Copy link
Copy Markdown
Member

I have to think about this but I think i'm fine with this. Seems a popular feature justifying adding an exception. It also feels very unlikely that someone writes a comment starting with |

@DavisVaughan

Copy link
Copy Markdown
Contributor Author

@MichaReiser thanks for giving it some consideration. I felt this could at least get some conversation going. I work with the Quarto team, so please let me know if you have any follow up questions!

@astral-sh-bot

astral-sh-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser added the notebook Related to (Jupyter) notebooks label Jun 5, 2026
@MichaReiser MichaReiser changed the title Add | to the list of allowed comment start characters Preserve whitespace for quorto notebook option comments. Jun 5, 2026
@MichaReiser MichaReiser changed the title Preserve whitespace for quorto notebook option comments. Preserve whitespace for quorto notebook option comments Jun 5, 2026
@MichaReiser MichaReiser changed the title Preserve whitespace for quorto notebook option comments Preserve whitespace for Quarto cell option comments Jun 5, 2026
@MichaReiser
MichaReiser merged commit 63cef3f into astral-sh:main Jun 5, 2026
44 checks passed
@MichaReiser

Copy link
Copy Markdown
Member

Thanks for proposing and implementing this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the formatter notebook Related to (Jupyter) notebooks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Quarto-style comment blocks

3 participants