Utilities that help you go from .ipynb -> .md
We can use nb2md
to convert a notebook to a markdown file with an Exporter
. Below, we use the exporter given to us by nbdoc.mdx.get_mdx_exporter
and use that to create a markdown file from a notebook.
_test_fname = Path('test_files/example_input.ipynb')
_test_dest = Path('test_files/example_input.md')
_test_dest.unlink(missing_ok=True)
assert not _test_dest.exists() # make sure the markdown file doesn't exist
nb2md(fname=_test_fname, exp = get_mdx_exporter()) # create the markdown file
assert _test_dest.exists() # make sure the markdown file does exist
assert len(_test_dest.readlines()) > 10
!cat {_test_dest}
You can use parallel_nb2md
to recursively convert a directory of notebooks to markdown files.
_test_nbs = nbglob('test_files/')
parallel_nb2md('test_files/', exp=get_mdx_exporter(), recursive=True)
for f in _test_nbs:
assert f.with_suffix('.md').exists(), f'{str(f)} does not exist.'
The modified times of notebooks are introspected such notebooks that haven't changed after markdown files have been created will not be converted:
parallel_nb2md('test_files/', exp=get_mdx_exporter(), recursive=True)
However, you can set force_all
= True
to force notebooks to convert:
parallel_nb2md('test_files/', exp=get_mdx_exporter(), recursive=True, force_all=True)