migrate

Utilities for migrating to nbdev

Convert fastpages blog posts to nbdev

Migrate notebooks


migrate_nb_fm

 migrate_nb_fm (path, overwrite=True)

Migrate fastpages front matter in notebooks to a raw cell.

_nb = migrate_nb_fm('../tests/2020-09-01-fastcore.ipynb', overwrite=False)
print(_get_raw_fm(_nb))
---
aliases:
- /fastcore/
author: <a href='https://twitter.com/HamelHusain'>Hamel Husain</a>
categories:
- fastcore
- fastai
comments: true
description: A unique python library that extends the python programming language
  and provides utilities that enhance productivity.
image: images/copied_from_nb/fastcore_imgs/td.png
title: 'fastcore: An Underrated Python Library'

---
_nb = migrate_nb_fm('../tests/2020-02-20-test.ipynb', overwrite=False)
print(_get_raw_fm(_nb))
---
aliases:
- /jupyter/2020/02/20/test
categories:
- jupyter
comments: true
description: A tutorial of fastpages for Jupyter notebooks.
image: images/chart-preview.png
title: Fastpages Notebook Blog Post

---

Migrate Markdown Files


migrate_md_fm

 migrate_md_fm (path, overwrite=True)

Make fastpages front matter in markdown files quarto compliant.

Here is what the front matter of a markdown post looks like before:

print(run('head -n13 ../tests/2020-01-14-test-markdown-post.md'))
---
toc: true
layout: post
description: A minimal example of using markdown with fastpages.
categories: [markdown]
title: An Example Markdown Post
---
# Example Markdown Post

## Basic setup

Jekyll requires blog post files to be named according to the following format:

And this is what it looks like after:

_res = migrate_md_fm('../tests/2020-01-14-test-markdown-post.md', overwrite=False)
print(_res[:300])
---
aliases:
- /markdown/2020/01/14/test-markdown-post
categories:
- markdown
description: A minimal example of using markdown with fastpages.
title: An Example Markdown Post

---
# Example Markdown Post

## Basic setup

Jekyll requires blog post files to be named according to the following format:

Convert nbdev v1 projects to nbdev v2

Directives

nbdev v2 directives start with a #| whereas v1 directives were comments without a pipe |.


_repl_directives

 _repl_directives (code_str)

for example, if any of the lines below are valid nbdev v1 directives, they replaced with a #|:

Callouts

In fastpages, there was a markdown shortuct for callouts for Note, Tip, Important and Warning with block quotes. Since Quarto has its own callout blocks with markdown syntax, we do not implement these shortcuts in nbdev. Instead, we offer a manual conversion utility for these callouts so that you can migrate from fastpages to Quarto.


_convert_callout

 _convert_callout (s)

Convert nbdev v1 to v2 callouts.

For example, the below markdown:

_callouts="""
## Boxes / Callouts

> Warning: There will be no second warning!

Other text

> Important: Pay attention! It's important.

> Tip: This is my tip.

> Note: Take note of `this.`
"""

Gets converted to:


## Boxes / Callouts

:::{.callout-warning}

There will be no second warning!

:::

Other text

:::{.callout-important}

Pay attention! It's important.

:::

nbdev_migrate

 nbdev_migrate (fname:str=None, disp:bool=False, stdin:bool=False,
                no_skip:bool=False)

Convert all directives and callouts in fname from v1 to v2

Type Default Details
fname str None A notebook name or glob to migrate
disp bool False Print the outputs with newly formatted directives
stdin bool False Read notebook from input stream
no_skip bool False Do not skip directories beginning with an underscore