MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Using tags to define admonitions

Open psychemedia opened this issue 3 years ago • 0 comments

Describe the problem/need and solution

Currently, notebook cell tags can be used to control cell display (for example, Hiding cell tags).

Admonition blocks are also used to style content direclty in the markdown using specially fenced code blocks.

It would make for cleaner markdown within a cell if a cell tag could be used to define at least simple admonition blocks.

For example, the following code fragment shows how we can map bootstrap alert- tags onto Jupyter Book styling:

for i, cell in enumerate(nb['cells']):

                    #For each markdown cell
                    if cell['cell_type']=='markdown' and 'tags' in nb['cells'][i]["metadata"]:
                        # We'll capture tags per cell
                        tags = nb['cells'][i]["metadata"]['tags']
                        source = nb['cells'][i]['source']

                        if 'alert-success' in tags:
                            nb['cells'][i]['source'] = f":::{{admonition}} Note\n:class: tip\n{source}\n:::"

image

For simple admonitions(eg note, important etc), it would be useful if an author could tag a cell correspondingly and then render it as the appropriate admonition block.

So for example, content in a markdown block tagged note would be parsed into a ```note admonition block.

The executablebooks/jupyterlab-myst already supports rendering of Myst content, such as admonition blocks, so to support WYSIWYM editing, a Jupyerlab / Retrolab extension, or the MyST parser, would be required to parse tagged cells into structured MyST.

psychemedia avatar Mar 03 '22 11:03 psychemedia