Skip to content

Generate MyST AST from cell execution #1633

@choldgraf

Description

@choldgraf

The executable plugins documentation for directives shows how you can return MyST AST by printing to stdout in order to generate different types of MyST outputs.

Users should be able to do the same thing via {code-cell} directives and Jupyter Notebook cells. This would allow users to more flexibly generate MyST AST without requiring any kernel-specific libraries (since you'd just be using stdout).

Implementation ideas

Doing it with tags

One approach could be to use cell tags to tell MyST when to capture a cell's output and treat it as MyST AST.
Here's an example of what this could look like:

```{code-cell} python
:tags: output-myst-ast
ast = {
      "type": "list",
      "ordered": false,
      "spread": false,
      "children": [
        {
          "type": "listItem",
          "spread": True,
          "children": [
            {
              "type": "strong",
              "children": [
                {
                  "type": "text",
                  "value": "Bolded"
                }
              ]
            },
            {
              "type": "text",
              "value": " list item"
            }
          ]
        }
      ]
    }
print(ast)
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions