jupytext
jupytext copied to clipboard
Code cells with tildes and double newline breaks .md to .ipynb conversion
Hi, I realized that using tildes and double newline for markdown breaks conversion to ipynb. I'm using jupytext 1.13.0.
Example (double newline between import and def):
~~~python
import math
def x():
pass
~~~
Generates ipynb:
{
"cells": [
{
"cell_type": "markdown",
"id": "1ef9d2ed",
"metadata": {},
"source": [
"~~~python\n",
"import math"
]
},
{
"cell_type": "markdown",
"id": "6384c75c",
"metadata": {},
"source": [
"def x():\n",
" pass\n",
"~~~"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
This does not happen if I remove the double newline. It also works fine if I use backticks.
Attaching files to reproduce the error and the output ipynb files: jupytext.zip
Hi @edublancas , yes sorry about that, Jupytext does not recognize code cells with tildes. For this reason you get a first markdown cell. And then, in the plain Jupytext Markdown format, two blank lines are understood as a Markdown cell break, so you get a second markdown cell...
So... may I ask if you have a reason to prefer ~~~python over ```python?
If so, did you try the md:myst format? Tildes might work better there (keep us posted!)
I'm using tildes because the docs mention that you can use them if you don't want Jupyter to recognize them as code cells (I have some .md files where some snippets are just informative, not meant to be executed). The docs suggest a few ways to do this and using tildes seemed like the cleanest one. In the end, I used backticks and the <!-- #md --> markers.
That's why I thought it was a bug, but if that's the intended behavior maybe remove the suggestion to use tildes in the docs? (happy to open a PR)
I'm using tildes because the docs mention that you can use them if you don't want Jupyter to recognize them as code cells
Oh sure, I see! Thanks for confirming. I'll have a look and see if I can write a fix for this.
Awesome, thanks!