Years ago, I wrote the `sage -rst2sws` script and the first version of `sage -rst2ipynb` in sage with the help of Thierry Monteil. But this was bringing a lot of dependencies and packages to be installed (pandoc, etc.) Also, at some point it got broken and I thought it still was broken today. But, I just checked and it seems to work now! Here is what I did:
Note that I am using an old version:
$ sage -v
SageMath version 10.6.beta7, Release Date: 2025-02-21
$ sage -rst2ipynb -h
/home/slabbe/GitBox/sage/src/bin/sage: ligne 854: rst2ipynb : commande introuvable
rst2ipynb is not installed, please run "sage -i rst2ipynb"
$ sage -pip install rst2ipynb
Collecting rst2ipynb
Downloading rst2ipynb-0.2.3-py3-none-any.whl.metadata (2.5 kB)
Collecting notedown (from rst2ipynb)
[...]
Installing collected packages: pandoc-attributes, notedown, rst2ipynb
Successfully installed notedown-1.5.1 pandoc-attributes-0.1.7 rst2ipynb-0.2.3
$ sage -rst2ipynb -h
usage: rst2ipynb [-h] [-o OUTPUT] [-k KERNEL] [-v] [-d] [input] [output]
Convert a reStructuredText (.rst) file to a Jupyter notebook (.ipynb)
positional arguments:
input input file (default: read from standard input)
output output file (default: write to standard output)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
output file
-k KERNEL, --kernel KERNEL
sets the Jupyter kernel in the notebook
-v, --verbose be verbose
-d, --debug write debug information and keep temporary .md file
$ vim file.rst
$ cat file.rst
title
=====
Testing a cell::
sage: 4 + 5
9
Testing latex : $\alpha$
Testing latex differently: `\alpha`
$ sage -rst2ipynb yo.rst yo.ipynb
$ sage -n
It works: