mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

Parse markdown code-cell outputs such that they participate in the MyST build

Open choldgraf opened this issue 1 year ago • 14 comments

Jupyter notebook cells can produce text output that is specific to markdown (text/markdown). It'd be useful if MyST could parse this output along with the rest of the markdown in the notebook. This would allow for programmatic generation of notebook content, and along with the {embed} directive could allow you to nicely stitch together MyST content via any Jupyter Kernel.

For example:

CleanShot 2024-03-22 at 11 05 46@2x

As an example, the MyST-nb Sphinx extension documents this functionality here.

An example from our docs where this would be useful

In the admonitions docs here:

https://github.com/executablebooks/mystmd/blob/c0f51ee51890158081736722cb01bcf510699786/docs/admonitions.md?plain=1#L34-L98

We have a big list of all the different types of admonitions for demonstration. It's just boilerplate myst repeated over and over. If we parsed Markdown outputs as MyST, we could replace it with something like:

inner = []
for admonition in ["note", "tip", "warning"]:
	s = """
	````{tab-item}
    ```{%s}
    This is an %s admonition. 
    ```
    ````
    """ % admonition
	inner.append(s)
template = """
`````{tab-set}
%s
````` % "\n".join(inner)
"""

Related

  • https://github.com/jupyter-book/mystmd/issues/1633

choldgraf avatar Mar 22 '24 18:03 choldgraf