jupyterlite / jupyterlite-sphinx

Sphinx extension using JupyterLite to render Notebooks
https://jupyterlite-sphinx.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
67 stars 20 forks source link

Support Jupytext (MyST-Markdown flavoured) notebooks in `NotebookLite`, `JupyterLite`, and `Voici` directives #191

Open agriyakhetarpal opened 1 month ago

agriyakhetarpal commented 1 month ago

Problem

jupyterlite-sphinx does not yet support Jupytext (Markdown) notebooks in its directives. Markdown notebooks are a wonderful solution to existing notebook tooling designed for IPyNB notebooks, which are hard to conquer for traditional version control systems like Git. One of the advantages of notebooks as text-based formats is that they pair up nicely with Markdown-based documentation tooling along with Sphinx and are supported for execution and for other standards in the ecosystem as well.

Proposed Solution

This feature request is copied over from the proposal added in https://github.com/jupyterlite/jupyterlite-sphinx/pull/180#issuecomment-2192628783 as a corollary to the functionality provided and now available since v0.16.0 (release):

The Jupyter extension, Jupytext, provides an API in addition to its CLI. Another worthwhile feature to add to jupyterlite-sphinx would be to allow the .. notebooklite::, ..jupyterlite::, and the ..voici:: directives to accept text-based Markdown notebooks – jupytext as a dependency can then be used with its API to convert the notebook from .md at jupyterlite-sphinx's runtime (maybe even by default, and not opt-in), and then pass/copy it as .ipynb to JupyterLite.

It is to be noted that the JupyterLite interface does have support for Jupytext, but I am not sure if the Markdown notebook is currently runnable – it is not supported right now, based on this discussion: https://github.com/jupyterlite/jupyterlite/discussions/731, so this conversion from .md to .ipynb at build time could be a reasonable temporary solution for notebook authors until JupyterLite itself can gain support. We can instruct users in the documentation and let them be aware through the means of an admonition that their notebooks are available in the JupyterLite interface as IPyNB, even if they pass them in their directives as Markdown. Some use cases are available in the "Additional context" section below.

Additional context

cc @melissawm and @steppi

agriyakhetarpal commented 1 month ago

Also, since jupyterlite-sphinx has not had a v1 release yet, we could make this an experimental feature by mentioning it as such in the documentation and enabling it only via a jupyterlite_experimental boolean config value in conf.py – similar to how scikit-build-core enables experimental features in pyproject.toml, therefore making this opt-in instead of opt-out in the meantime while Jupytext support matures.