mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

support frontmatter in raw Jupyter notebook cells (in addition to markdown cells)

Open itcarroll opened this issue 7 months ago • 1 comments
trafficstars

CC @mwouts

Proposal

MyST frontmatter must currently be included in Jupyter notebooks as a leading markdown cell. Would you also support including frontmatter in Jupyter notebooks as a leading raw cell? This enhancement would further improve the user experience with Jupytext and the "md:myst" text format for Jupyter notebooks. As of Jupytext version 1.17.0rc2, a Jupyter notebook beginning with MyST frontmatter in a raw cell gets written to the "md:myst" text format with a single YAML block (a markdown cell yields two YAML blocks, as it always has). With MyST frontmatter in a single YAML block in the "md:myst" text format, the text file itself becomes usable with MyST.

The proposal will allow Jupytext to pair standard MyST markdown files with Jupyter notebooks while keeping all frontmatter and metadata usable and relevant in both formats. It could further the uptake by JupyterLab users of MyST markdown.

Additional notes

I authored the relevant enhancement to Jupytext available for testing in 1.17.0rc2. The use of raw cells was a deliberate choice to avoid breaking existing "md:myst" formatted files that include frontmatter in markdown cells, but makes sense for other reasons (e.g. YAML headers get ugly with non-MyST renderers like GFM).

I suppose it may be sufficient for only jupyterlab-myst to handle any leading raw cell, but I think it would be less confusing if the whole myst ecosystem treated leading raw and markdown cells equivalently.

itcarroll avatar Mar 31 '25 20:03 itcarroll

Thanks @itcarroll, we did have this implemented like this at one point (very) early on. I am struggling to remember why we limited it to md-cells, if that was a deliberate choice, and/or perhaps an artifact of the JupyterLab-MyST plugin which was easier to override the markdown renderer only.

I would be happy to revisit this and improve compatibility with Jupytext.

rowanc1 avatar Mar 31 '25 20:03 rowanc1

IMO it is reasonable to support Yaml front matter in a raw cell. The --- front matter convention isn't strictly markdown, so it feels just as reasonable to allow it to be a raw cell. If it improves compatibility with jupytext and matches what quarto allows, that's an even better reason to allow this.

So I'd suggest that, unless somebody comes up with a risk that we haven't considered and that would be a big deal, we consider this "ready for somebody to implement".

choldgraf avatar Apr 27 '25 15:04 choldgraf