def generate_clrs(): clrs_path = Path('docs/CLRS') nb_files = sorted(clrs_path.glob('**/*.ipynb')) for nb_file in nb_files: md_exporter = MarkdownExporter() with open(nb_file) as f: markdown, _ = md_exporter.from_file(f) title = nb_file.stem md_file = nb_file.parent / f'{title}.md' print(md_file) md_file.write_text(markdown)
f for f in os.listdir(src_path) if os.path.isfile(os.path.join(src_path, f)) ] print(os.listdir(src_path)) target_notebooks = list( map( lambda f: { 'name': f, 'path': os.path.join(src_path, f) }, list( filter( lambda f: f.endswith('.ipynb') and not f.endswith( '.draft.ipynb'), files)))) md_exporter = MarkdownExporter() # md_exporter.template_file = 'basic' for nb in target_notebooks: nb['body'], nb['resources'] = md_exporter.from_file(nb['path']) print(nb['resources']) pre, _ = os.path.splitext(nb['name']) nb['out_path'] = os.path.join(dist_path, pre + '.md') os.makedirs(dist_path, exist_ok=True) with open(nb['out_path'], 'w') as out: out.write(nb['body'])
def convert_markdown(nb_path): """ Convert a notebook to markdown """ markdown_exporter = MarkdownExporter() return markdown_exporter.from_file(str(nb_path))