Skip to content

Commands to convert between .ipynb and .qmd#955

Merged
seeM merged 14 commits intoquarto-dev:mainfrom
seeM:feat/vscode-convert-command
Apr 30, 2026
Merged

Commands to convert between .ipynb and .qmd#955
seeM merged 14 commits intoquarto-dev:mainfrom
seeM:feat/vscode-convert-command

Conversation

@seeM
Copy link
Copy Markdown
Collaborator

@seeM seeM commented Apr 26, 2026

Closes #6.

This PR adds two commands to convert between .ipynb and .qmd using the quarto convert CLI. The motivation is to ease the onboarding process for Positron users coming from Jupyter Notebooks who are interested in trying out Quarto, and vice versa (posit-dev/positron#11865).

Both commands are available in the command palette and in the UI:

  • quarto.convertToIpynb: available in source and visual editor overflow menus, under a new group at the bottom
  • quarto.convertToQmd: available in notebook editor overflow menu (both VS Code notebook editor and Positron notebook editor), under a new group at the bottom

The commands follow the same process:

  1. Save the document
  2. Check if converting would overwrite a file and prompt the user with a modal dialogue
  3. Convert the document
  4. Show any tidied up CLI errors
  5. Open the converted document

Tests are included.

In future, I plan to add a command to Positron tentatively named quarto.initializeFromIpynb that the quarto.convertToQmd calls before opening the created .qmd file to set the kernel binding and fill the output cache using the original .ipynb file for a more seamless transition.

Comment thread apps/vscode/.vscode-test.mjs
Comment thread apps/vscode/package.json
Comment thread apps/vscode/package.json
Comment thread apps/vscode/src/test/r-project.test.ts
@cderv cderv requested a review from cscheid April 27, 2026 08:23
Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! I have three questions/thoughts:

  • Can we improve how error messages get surfaced to the user in terms of escaping? For example, if I have a Quarto file like this:
---
title: "unclosed
format: html
---

content

And I run the new command, I get this popup, which is not ideal:

Image
  • When I convert a .qmd to an .ipynb, it always opens up the new file in a regular text editor for the JSON, not a notebook editor:
Image

Can we open the new .ipynb files in the default notebook editor the user has configured? Either the legacy one or the new Positron notebook editor?

  • Can you update the CHANGELOG with info on this new feature?

Comment thread apps/vscode/src/providers/convert.ts Outdated
seeM added 12 commits April 28, 2026 19:59
…test config so it's easier to run alone and shows in vscode extension test runner ui
Register `quarto.convertToIpynb` and `quarto.convertToQmd` commands that wrap `quarto convert`
to convert between .qmd and .ipynb formats. Includes overwrite confirmation,
error handling with output channel logging, and editor context menus.
@seeM seeM force-pushed the feat/vscode-convert-command branch from 4f4103e to b24fdb2 Compare April 28, 2026 17:59
@seeM
Copy link
Copy Markdown
Collaborator Author

seeM commented Apr 28, 2026

Thanks, great catches.

  1. The error message now shows only the initial message, and the user can click the Show Output button to see the full error with stack trace (375790c)

    image
  2. Now uses the vscode.open command so it uses the default editor for the file extension, tested with positron.notebook.enabled on and off (7a3cd5a)

  3. Updated the changelog (b24fdb2)

@seeM seeM requested a review from juliasilge April 28, 2026 18:03
Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good and is ready to merge! 🙌

I want to highlight that if we start sticking a button for this on files in Positron, we are going to come up hard against some of what doesn't work well with quarto convert. There are a bunch of situations where it doesn't work well, but here is one example.

Make an R notebook:

Image

Convert and you get this:

---
jupyter: python3
---

Here is my great notebook! It will use janitor 🧼🧹

```{python}
library(tidyverse)
library(janitor)

gapminder::gapminder |> 
  clean_names() |> 
  drop_na()
```

This isn't a problem with this PR but with quarto convert but we will want to be very careful about where we surface this functionality with a button. We want to only put it somewhere that we think it will work well. Maybe no R? And maybe no .qmd files, as the conversion from .qmd to .ipynb is worse than the other way IMO.

@seeM
Copy link
Copy Markdown
Collaborator Author

seeM commented Apr 29, 2026

@juliasilge interesting. What do you think about us fixing those sorts of issues if they come up?

@juliasilge
Copy link
Copy Markdown
Collaborator

@seeM Those would need to be fixed in the core of the Quarto CLI, not the extension:

https://github.com/quarto-dev/quarto-cli/issues?q=is%3Aissue%20state%3Aopen%20%22quarto%20convert%22

You are advocating we fix them in the Quarto CLI?

quarto convert is broken enough in enough situations that I don't think we can put a button on, say, a .qmd file with R code. Please try it out and see what I mean! I think we'll do better contributing a button in a situation where we think it will work (like an .ipynb that uses a Python kernel).

@juliasilge
Copy link
Copy Markdown
Collaborator

You can read some more background here: https://github.com/orgs/quarto-dev/discussions/9463

@seeM seeM merged commit b36fe9c into quarto-dev:main Apr 30, 2026
4 checks passed
@seeM seeM deleted the feat/vscode-convert-command branch April 30, 2026 16:56
@cscheid
Copy link
Copy Markdown
Member

cscheid commented Apr 30, 2026

(Just for everyone's awareness, we definitely want to fix these issues; Wasim and I are meeting early next week about this.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add quarto convert command

3 participants