quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
344 stars 30 forks source link

Could the 'Quarto: Format Cell' command work for Observable? #500

Open jack-davison opened 4 months ago

jack-davison commented 4 months ago

I understand that the VSCode/Positron extension can style Py/R code, but not OJS. It'd be really helpful if it could do OJS too! e.g., turn

```{ojs}
Plot.plot({
marks: [
        Plot.dot(transpose(iris), {x: "Sepal.Length", y: "Petal.Width"})
        ]
})

into 

````qmd
```{ojs}
Plot.plot({
    marks: [
        Plot.dot(transpose(iris), {x: "Sepal.Length", y: "Petal.Width"})
    ]
})


Directed from https://github.com/posit-dev/positron/discussions/4196. Original message on the Positron repo from Julia Silge:

> The solution to this will need to come from the Quarto extension, since it provides formatting for `.qmd` files. They have a command to format a cell:
> 
> ![Screenshot 2024-07-31 at 12 42 07 PM](https://private-user-images.githubusercontent.com/12505835/353953752-2ee220c3-5b06-48b4-a002-accd12da9e9d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI0NTQwNjUsIm5iZiI6MTcyMjQ1Mzc2NSwicGF0aCI6Ii8xMjUwNTgzNS8zNTM5NTM3NTItMmVlMjIwYzMtNWIwNi00OGI0LWEwMDItYWNjZDEyZGE5ZTlkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzMxVDE5MjI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjMDRkNDgyODc4ZDA1NDkxODJmNTc3OWYxMDQwNjFhNzI3OGE4ZTYxNTgwZjMzMzYwNzQ1ZTQzNjNmNmQ1ZmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.LWfBxdBBAXvtQkFRCwcgj0ygRGK3G4NmT-HxSGQQhlY)
> 
> Unfortunately though, that does not yet work for Observable chunks (it _does_ work for R and Python). Can you open an issue on the repo for the Quarto extension that you would like the "Quarto: Format Cell" command to work for Observable? https://github.com/quarto-dev/quarto/issues

Cheers,
Jack
cscheid commented 3 months ago

This will be a bit hard for us to do, because there's no standard formatter for the OJS syntax, afaict. OJS is not JS (see, eg, the mutable keyword), and so we'd have to wait for other developers to create appropriate tooling first.