Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/nbs/blog_test.ipynb
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Blogging with Jupyter Notebooks\n\n> With Notebooks, we can easily share prose, code, tables, charts, and more!"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Jupyter Notebooks is a great environment for creating blog posts. Or maybe you didn't even plan to write a blog post, but you've done some interesting experiments and you realize afterwards that you have results worth sharing. Either way, you'll want some way to get your Notebook onto your blog.\n\n[fast_template](https://www.fast.ai/2020/01/16/fast_template/) and [nbdev](http://nbdev.fast.ai/) are set up to handle Jupyter Notebooks nicely, so there's not much you have to do to get this working. I'll walk you through the steps here. Note that Jupyter Notebooks and GitHub Pages already have some support for exporting notebooks to markdown; but I suggest you use `fast_template` and `nbdev`, with the process described in this post, because otherwise you won't get useful features such as:\n\n- Support for pasting images directly into your notebook\n- Input and output cells clearly displayed with appropriate styles\n- The ability to hide some cells from the markdown output.\n\nThis whole post was created using this method. You can see the source notebook here:"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Writing your notebook"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Your markdown cells, code cells, and all outputs will appear in your exported blog post. The only thing that won't be shown is interactive outputs (e.g. `ipywidgets`, bokeh plots, etc), or cells you explicitly hide using the `#hide` marker discussed below.\n\nWhen you write your notebook, just write whatever you want your audience to see. Since most writing platforms make it much harder to include code and outputs, many of us are in a habit of including less real examples than we should. So try to get into a new habit of including lots of examples as you write.\n\nOften you'll want to hide boilerplate such as import statements. Add `#hide` to the top of any cell to make it not show up in output."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "#hide\nfrom fastai2.vision.all import *",
"execution_count": 14,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Jupyter displays the result of the last line of a cell, so there's no need to include `print()`. (And including extra code that isn't needed means there's more cognitive overhead for the reader; so don't include code that you don't really need!)"
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "1+1",
"execution_count": 3,
"outputs": [
{
"data": {
"text/plain": "2"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "It works not just for text, but also for images:"
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "Image.open('../fast.ai/images/fast_template/image2.png').flip_lr()",
"execution_count": 23,
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQMAAABjCAIAAAAQMPJyAAANG0lEQVR4nO3df0zUd57H8ed8KcwPfgwo+FXRG+p2T8sZqKtFzjOduNypqQZjNXZPbmmuNF5ST66pZ7Nds3MJjdvc9dbc0ri5Ja5JbbAtqXtxdu2hnmdoiafsVYsxFNMuP2wpjqDAwDAz0PnO/fHtIQwgA8MPZ3g/wj/MfOb7/XyHeX0/n8/385kvIIQAAxAMBue6GkLMoJavvgGyli8dr4DBYFBmsT5CPLokCUKAJEEInSRBCJAkCKF7DOi41z3X1RBijkmbIATobUJSUuJcV0OIGeTp75+wjLQJQoAkQQidJEEIkCQIoZMkCAGSBCF0kgQhQJIghE6SIARIEoTQSRKEAEmCEDpJghAgSRBCJ0kQAiQJQugkCUKAJEEInSRBCJAkCKGTJAgB+r0thJhp1xparn3eOtlXmUwJu/5yrdmYMBNVCiFJEDPuWkPL6f/6dGqvPeUfLHnumemtz5iiLwl1UFD6Ffi/fFZRt66Y6+rMkqLqXudHLgccKk+F9JnbkQtKfuVqaeyt3Kjk7lkKpgg3ePFqw39f/RxYkm598nvj/geD0bp6+q83tjZ93RFhBcIUfUkQM6rGRU2jBzhfq+Xu6YswCacvfHrt8xZgSbq1ZNczk+rnNLd1Xm+cdIdqymTELEawq9hXJdrAnq9AUiSbiiQGs0/aBDGCCr9/WQU1wu1EVwyQJIiZMBSDFcsy9m7LHzMGXT2ert6xb1ealmxJs872vXolCWKaDcVgzSrb7s3rxit2rbFVH0mP9sP1Txasz56h6o1HxglimoUTg0dQ1LcJFX/o/eD8/TrXIG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aJiPmSA0faks8wmQ2Jvx4+4a5rsWkSRLGNrxtkZHGfBDF646EmEbzrk0IuaAx5vWNkNk3MR/Efpswhc+0xGAemndtwmTJpaR5IvbbBCHCIUkQAiQJo8ks2/wkSRACJAlC6OTa0dj0eWXpGs0fsZYE/bMbssxOiAnFWhKmhQyUY09c3AQDARkniHnBbBrjtuTDSRLEvJBomeALqJKEUNI1ij0pyYlm0xj/QWK4x/j/b/TEkubbbZEMmmPvDZnPUpITF6SO8b+XQsiIWcSmuDjFbDIlWswTtga60G/xxowptAmjv9Ms5gmDwSDjBCFAekdDZDJunpM2QQiQJAihi+XekdydRYQvZpMgnX4xKdI7EgIkCULoJAlCgCRBCJ0kQQiQJAihkyQIAZIEIXSSBCFAkiCEEOKB/wPZr9Kfv6wfTwAAAABJRU5ErkJggg==\n",
"text/plain": "<PIL.Image.Image image mode=RGB size=259x99 at 0x7F3E30E4CA50>"
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "...and plots:"
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "plt.plot([1,2]);",
"execution_count": 24,
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deViVdf7/8edHBRVEXHBHxA030FKUbLVsSs0W05lq2q2sptm/k5pWWjZlNk3TjJVjTYutMwkuadlqaaWVVrIpirihKCgKyA7n8/sDfnM5pnKUc7g557we18UVeN+e+3V74NXNfe77fYy1FhER8X1NnA4gIiKeoUIXEfETKnQRET+hQhcR8RMqdBERP9HMqQ1HRETY6OhopzYvIuKTNm7ceNBa2+FEyxwr9OjoaDZs2ODU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v7/Nx636Oj1/l4ubzbIC/AulACnC905kbYJ8HAl9RcwXMj8BlTmeu5/6+DeQAldQcjd8B3APcc8xz/Fztv0eKJ76vdeu/iIifaMynXERE5DSo0EVE/IQKXUTET6jQRUT8hApdRMRPqNBFRPyECl1ExE/8P6t93d4+JfYsAAAAAElFTkSuQmCC\n",
"text/plain": "<Figure size 432x288 with 1 Axes>"
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "...and Pandas DataFrames, and much more!"
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "pd.DataFrame({'a':[1,2], 'b':[3,4]})",
"execution_count": 7,
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>a</th>\n <th>b</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>3</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>4</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " a b\n0 1 3\n1 2 4"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can also paste images, such as screenshots, directly into a markdown cell in Jupyter. This creates a file embedded in the notebook that Jupyter calls an \"attachment\". Or you can use Markdown to refer to an image on the internet by its URL."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "![](https://upload.wikimedia.org/wikipedia/commons/1/1b/Creative-Tail-Animal-dog.svg)"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Exporting to markdown"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Before you export to markdown, you first need to make sure your notebook is saved, so press `s` or click `File`➡`Save`. Then close the browser tab with the open notebook. This is important, because when we export to markdown any attachments will be exported to files, and the notebook will be updated to refer to those external files. Therefore, the notebook itself will change; if you leave it open, you may accidentally end up overwriting the updated notebook.\n\nYou'll need `nbdev` installed; if you haven't already, then install it with:\n\n pip install nbdev\n\nThen, in your terminal, cd to the folder containing your notebook, and type (assuming your notebook is called `name.ipynb`):\n\n nbdev_nb2md name.ipynb\n\nYou'll see that a file `name.md` and folder `name_files` have been created (where \"name\" is replaced by your notebook file name). One problem is that the markdown exporter assumes your images will be in `name_files`, but on your blog they'll be in `/images/name_files`. So we need to do a search and replace to fix this in the markdown file. We can do this automatically with python. Create a file called `upd_md.py` with the following contents:\n\n```python\nimport fileinput,re\nfor f in fileinput.input(inplace=True):\n print(re.sub(r'^(!.*]\\()(\\w+_files/)', r'\\1/images/\\2', f), end='')\n```\n\nThen, in the terminal, run (assuming that `upd_md.py` and your markdown doc are in the same folder):\n\n python upd_md.py name.md\n\nThis will modify your markdown doc inplace, so it will have the correct `/images/` prefix on each image reference."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Finally, copy `name_files` to the `images` folder in your blog repo, and `name.md` to your `_posts` folder, and rename `name.md` to have the required `YEAR-MONTH-DAY-name.md` format. Commit and push this to GitHub, and you should see your post!"
}
],
"metadata": {
"jupytext": {
"split_at_heading": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.5",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"toc": {
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": true,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"gist": {
"id": "",
"data": {
"description": "/nbs/blog_test.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@gsanc018

This comment has been minimized.

Copy link

gsanc018 commented Jan 21, 2020

I'm getting a syntax error?
File "upd_md.py", line 3 print(re.sub(r'^(!.*]\()(\w+_files/)', r'\1/images/\2', f), end='') ^ SyntaxError: invalid syntax

I just copied and pasted ):

@jph00

This comment has been minimized.

Copy link
Owner Author

jph00 commented Jan 21, 2020

@gsanc018

This comment has been minimized.

Copy link

gsanc018 commented Jan 21, 2020

Ah yes, using python3 worked. Thanks a bunch!

@lecidhugo

This comment has been minimized.

Copy link

lecidhugo commented Jan 24, 2020

Hi,
After executing:
nbdev_nb2md name.ipynb
I only got name.ipynb but not the folder name_files although I included screenshots in name.ipynb. After commit, the screenshots are missed.
great work, btw :)

@mazeyang

This comment has been minimized.

Copy link

mazeyang commented Feb 1, 2020

Hi, after executing:

nbdev_nb2md name.ipynb

I got: ** UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 103: illegal multibyte sequence. **
I have set encoding like this:

for f in fileinput.input(inplace=True, openhook=fileinput.hook_encoded(encoding="utf-8")):

but this ERROR still occurs... what happened?

Thank you!

@mazeyang

This comment has been minimized.

Copy link

mazeyang commented Feb 1, 2020

Hi, after executing:

nbdev_nb2md name.ipynb

I got: UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 103: illegal multibyte sequence.
I have set encoding like this:

for f in fileinput.input(inplace=True, openhook=fileinput.hook_encoded(encoding="utf-8")):

but this ERROR still occurs... what happened?

Thank you!

@hargun3045

This comment has been minimized.

Copy link

hargun3045 commented Feb 14, 2020

After the command,
nbdev_nb2md blog_test.ipynb
If by chance anyone is getting the following error
AssertionError: Use create_config to create settings.ini for the first time
You will need a settings.ini file in the same directory as where you're running the command. Download settings.ini from here
For more information and help look here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.