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:
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
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-filtersoption in_quarto.ymland are essential to the nbdev project where directives such as#|exportselect code cells for compilation into a python library.quarto convertdoesn't work on notebooks designed to make use of this advanced feature.If an ipynb file had the code cell:
converting it into QMD will produce the cell:
and converting back will discard the directive completely:
Starting out with a correct
#|exportdirective in the QMD version of the file and attempting to convert the file into ipynb produces the following error: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