posit-dev / posit-dev/air

Air incorrectly formatting Python code cell in Quarto document

Open
#403 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
446
Forks
32
Avg merge
16h 48m
Merged PRs (30d)
1

Description

I am attempting to use Air in a repo that has some Quarto documents with both R and Python cells. It seems to recognize the Python cell is not R code and Air does not attempt to format it, but it incorrectly formats any Quarto options defined in the cell.

Reproducible example:

---
title: "Test"
format: html
---

```{r}
#| label: setup

library(tidyverse)
library(reticulate)
```

```{python}
#| echo: false

from sklearn.linear_model import LinearRegression
import pandas as pd
```

is formatted into

---
title: "Test"
format: html
---

```{r}
#| label: setup

library(tidyverse)
library(reticulate)
```

```{python}
# | echo: false

from sklearn.linear_model import LinearRegression
import pandas as pd
```

Notice Air is adding a space inside of #| so the line is no longer recognized by Quarto when you render the document

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided mixed R/Python Quarto document and inspect how Air processes options inside non-R cells. Verify the formatter's output for the Python cell, then add coverage for the shown example if the relevant test entry point is found. Done means R code is formatted while Quarto options such as #| echo: false remain renderable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, r
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.