Package: md2ipynb
md2ipynbMarkdown to Jupyter Notebook converter.Setup[optional] Virtual environmentMake sure you havevirtualenvinstalled.pipinstall-UvirtualenvCreate and activate a newvirtualenv.python-mvirtualenvenvsourceenv/bin/activateNote: Once you are all done, you can deactivate it by runningdeactivate.InstallationThe easiest way to install is throughpip.pipinstall-Umd2ipynbExample dataNow, to get some example data, we'll clone the repository.# Clone the repository just to have access to the examples.gitclonegit@github.com:davidcavazos/md2ipynb.gitcdmd2ipynbNote:If you make modifications to the source code and want to use that,
you can install it in "editable" (development) mode.pipinstall-e.For more information, see theContribution guide.Installing themd2ipynbmodule will also install themd2ipynbcommand line tool.
For custom preprocessing steps or integration with Python scripts,
it is also available by importing themd2ipynbmodule from any Python script.Minimal examplesource:hello.mdcode:hello-world.pyHere is a minimal example on how to convert a Markdown file.
By default, the output is printed intostdout.md2ipynbexamples/pages/hello.mdYou can also specify an output path with the-oor--outputoption.md2ipynbexamples/pages/hello.md-oexamples/notebooks/hello.ipynbHere is the generated notebook on Colab and GitHub.Run in ColabView on GitHubExamplesource:hello.mdcode:hello-world.pyimport:license.mdimport:setup-py.mdimport:cleanup.mdHere is a more complete example on specifying an output path, import sections,
variables, as well as more metadata for a Colab visualization.md2ipynbexamples/pages/hello.md\-oexamples/notebooks/hello.ipynb\--importsexamples/templates/license.md:0\examples/templates/setup-py.md:1\examples/templates/cleanup.md:-2\--varpackage=md2ipynb\end_message="You're all done 🎉🎉"\--notebook-title'Hello md2ipynb!'\--docs-urlhttps://github.com/davidcavazos/md2ipynb\--docs-logo-urlhttps://www.tensorflow.org/images/GitHub-Mark-32px.png\--github-ipynb-urlhttps://github.com/davidcavazos/md2ipynb/blob/master/examples/notebooks/hello.ipynbNote:For more information on the available options, runmd2ipynb --help.Here is the generated notebook on Colab and GitHub.
Note that since we specified the--github-ipynb-url,
there is now an "Open in Colab" button in the GitHub ipynb file.Run in ColabView on GitHubPython examplesource:hello.mdcode:hello-world.pyimport:license.mdimport:setup-py.mdimport:cleanup.mdThe following example shows how to usemd2ipynbas a Python module.
This example shows how to specify custom preprocessing steps, import sections,
use variables, as well as more metadata for a Colab visualization.importmd2ipynbdefadd_separators(paragraphs):forpinparagraphs:yield'---'yieldpyield'---'defreplace(paragraphs,old,new):forpinparagraphs:yieldp.replace(old,new)# Create a new IPython notebook.notebook=md2ipynb.new_notebook(input_file='examples/pages/hello.md',imports={0:['examples/templates/license.md'],1:['examples/templates/setup-py.md'],-1:['examples/templates/cleanup.md'],},variables={'package':'md2ipynb','end_message':"You're all done 🎉🎉",},notebook_title='Hello md2ipynb!',docs_url='https://github.com/davidcavazos/md2ipynb',docs_logo_url='https://www.tensorflow.org/images/GitHub-Mark-32px.png',github_ipynb_url='https://github.com/davidcavazos/md2ipynb/blob/master/examples/notebooks/hello.ipynb',# Additional steps can be run in the order specified.# If the generator receives multiple arguments, they can be passed as a tuple.steps=[add_separators,(replace,'Hello','Hi'),],)# Write the notebook to a file.importnbformatwithopen('examples/notebooks/hello-custom.ipynb','w')asf:nbformat.write(notebook,f)Here is the generated notebook on Colab and GitHub.Run in ColabView on GitHubContributingContributions are welcome! For instructions on how to contribute,
please check theContribution guide.