I want to programmatically create several markdown cells in a Jupyter notebook.
the following function works for code cells, but not markdown cells.
def create_new_cell(contents):
from IPython.core.getipython import get_ipython
shell = get_ipython()
payload = {
"source": "set_next_input",
"text": contents,
"replace": False
}
shell.payload_manager.write_payload(payload, single=False)
I try to add metadata setting, but it doesn't work.
def create_new_cell(contents):
from IPython.core.getipython import get_ipython
shell = get_ipython()
payload = {
"source": "set_next_input",
"text": contents,
"metadata": {"cell_type": "markdown"},
"replace": False
}
shell.payload_manager.write_payload(payload, single=False)
Is there any other solution?