Programmatically-generated markdown as seperate cells

I’m using jupyter book to display all my notebooks. I’m programmatically generating headers in a for loop as follows:

for i in range(10):
    display(Markdown(f'# Header {i}'))

The problem is that jupyter book expects the headers to appear as separate Markdown cells like this:

   "cell_type": "markdown",
   "source": [
    "# This is the header"

Is there a way to modify the cells during nbformat preprocessing in order to get separate Markdown cells for the items in the for loop? For lots of stuff I won’t know the headers in advance.

1 Like