Skip to content

Instantly share code, notes, and snippets.

@chsasank
Last active February 21, 2024 14:29
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save chsasank/7218ca16f8d022e02a9c0deb94a310fe to your computer and use it in GitHub Desktop.
Save chsasank/7218ca16f8d022e02a9c0deb94a310fe to your computer and use it in GitHub Desktop.
Convert jupyter notebook to sphinx gallery notebook styled examples.
@HealthyPear
Copy link

I had the opposite issue of @weber-s : my first cell was magic code so as a quick fixed I modified the first conditional block as

if cell["cell_type"] == "markdown":
    md_source = "".join(cell["source"])
    rst_source = pdoc.convert_text(md_source, "rst", "md")
    python_file = '"""\n' + rst_source + '\n"""'
elif cell["cell_type"] == "code":
    source = "".join(cell["source"])
    python_file = python_file + "\n" * 2 + source
else:
    raise ValueError(f"Unsupported starting cell type {cell["cell_type"]}.") 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment