def md_to_notebook(text):
    """Convert a Markdown text to a Jupyter notebook, using Pandoc"""
    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    tmp_file.write(text.encode('utf-8'))
    tmp_file.close()

    pandoc(u'--from markdown --to ipynb -s --atx-headers --wrap=preserve --preserve-tabs', tmp_file.name, tmp_file.name)

    with open(tmp_file.name, encoding='utf-8') as opened_file:
        notebook = ipynb_reads(opened_file.read(), as_version=4)
    os.unlink(tmp_file.name)

    return notebook
def md_to_notebook ( text ) : tmp_file = tempfile . NamedTemporaryFile ( delete = False ) tmp_file . write ( text . encode ( 'utf-8' ) ) tmp_file . close ( ) pandoc ( u'--from markdown --to ipynb -s --atx-headers --wrap=preserve --preserve-tabs' , tmp_file . name , tmp_file . name ) with open ( tmp_file . name , encoding = 'utf-8' ) as opened_file : notebook = ipynb_reads ( opened_file . read ( ) , as_version = 4 ) os . unlink ( tmp_file . name ) return notebook
Convert a Markdown text to a Jupyter notebook, using Pandoc