Skip to content

custom directives / ipynb-filters during quarto convert #3152

Closed
@githubpsyche

Description

@githubpsyche

Bug description

We can convert between .ipynb and .qmd representations of a notebook using the quarto convert command.

However, some notebooks have custom directives. These are normally supported during project compilation using the ipynb-filters option in _quarto.yml and are essential to the nbdev project where directives such as #|export select code cells for compilation into a python library.

quarto convert doesn't work on notebooks designed to make use of this advanced feature.

If an ipynb file had the code cell:

#| export
import numpy as np

converting it into QMD will produce the cell:

#| '0': e
#| '1': x
#| '2': p
#| '3': o
#| '4': r
#| '5': t
import numpy as np

and converting back will discard the directive completely:

import numpy as np

Starting out with a correct #|export directive in the QMD version of the file and attempting to convert the file into ipynb produces the following error:

> ERROR: TypeError: Cannot delete property '0' of [object String]

Ideally what would happen during a round-trip conversion is that the directives included at the top of code cells are preserved, just as natively supported directives are presented.

If quarto convert or some other tool could handle the round trip conversion between ipynb and qmd more cleanly, then nbdev projects and other tools utilizing the advanced nb-filter feature could use qmd source files for their work instead of jupyter notebooks! And the advantages of QMD over IPYNB as a format for work mixing text and code probably don't need to be outlined here.

Simple example file that quarto convert will struggle with:
https://gist.githubusercontent.com/githubpsyche/32c6391c30699bfd103b4992743b0af3/raw/a17f651cc28a9bb4f3afeab14bb9259ebc0bd0f6/example.ipynb

Using Windows 11. I believe I've tried this with the current release 1.1.251 and 1.2.253.

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions